It is showing the following error, even though I kept the condition for less then 3
When the array has less than three of the same number, your getHighestDuplicates function should update the final radio option with , score = 0.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
function getHighestDuplicates(arr){
let count={};
let score=0
arr.forEach(num=>{
count[num]=(count[num]||0)+1;
score+=num;
});
count.forEach(num=>{
if(n>=4){
updateRadioOption(1,score);
}else if(n>=3){
updateRadioOption(0,score);
}else if(n<3){
updateRadioOption(5,0);
}
updateRadioOption(5,0);
});
}
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
rollDice();
updateStats();
getHighestDuplicates(arr);
}
});
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7
function getHighestDuplicates(){
let count={};
let score=0
diceValuesArr.forEach(num=>{
count[num]=(count[num]||0)+1;
score+=num;
});
for(let n in count){
if(n >= 4){
updateRadioOption(1, score);
}else if(n >= 3){
updateRadioOption(0, score);
}
updateRadioOption(5, 0);
}
}
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
rollDice();
updateStats();
getHighestDuplicates();
}
});
but I am still getting the same error,
When the array has less than three of the same number, your getHighestDuplicates function should update the final radio option with , score = 0 .
The earlier points were really helpfull, thank you.
I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.