So i’ve been writing code for almost 6 hours and now mi issue is that getHighthestDuplicates seems to not be returning ,score=0 , but i tried to handle it with updateRadioOption(finalOptionIndex, 0); please help ;-;
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
function getHighestDuplicates(dice) {
let count = {};
let totalScore = dice.reduce((sum, num) => sum + num, 0);
for (let num of dice) {
count[num] = (count[num] || 0) + 1;
}
let hasFourOfAKind = false;
let hasThreeOfAKind = false;
for (let key in count) {
if (count[key] >= 4) {
hasFourOfAKind = true;
hasThreeOfAKind = true;
} else if (count[key] === 3) {
hasThreeOfAKind = true;
}
}
const threeOfAKindIndex = 0;
const fourOfAKindIndex = 1;
const finalOptionIndex = 2;
if (hasFourOfAKind) {
updateRadioOption(fourOfAKindIndex, totalScore);
updateRadioOption(threeOfAKindIndex, totalScore);
} else if (hasThreeOfAKind) {
updateRadioOption(threeOfAKindIndex, totalScore);
} else {
updateRadioOption(finalOptionIndex, 0);
}
}
function getCurrentDiceValues() {
return Array.from(listOfAllDice).map(die => parseInt(die.textContent));
};
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
rollDice();
let diceValues = getCurrentDiceValues();
getHighestDuplicates(diceValues);
updateStats();
}
});
// User Editable Region
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:134.0) Gecko/20100101 Firefox/134.0
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
rollDice();
updateStats();
getHighestDuplicates(diceValuesArr);
}
});
Already changed it and still giving me the 2. When the array has less than three of the same number, your
getHighestDuplicates
function should update the final radio option with