Tell us what’s happening:
I’ve found this task pretty difficult to follow. I thought that in calling the updateScore function at the end of the callback, I was updating the totalScore text however I’m still getting this as an error. I can’t figure out what’s going wrong.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
keepScoreBtn.addEventListener("click", ()=>{
let selectedValue;
let achieved;
for (const radioButton of scoreInputs){
if(radioButton.checked){
selectedValue = radioButton.id;
achieved = radioButton.value;
break;
}
}
if (selectedValue){
rolls = 0;
round++;
updateScore(selectedValue, achieved);
updateStats();
} else{
alert("Select an Option");
}
})
// 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/126.0.0.0 Safari/537.36 Edg/126.0.0.0
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 10
the first issue you have is here.
is the selectedValue (the value the user selected) really supposed to be brought from radioButton.id? (the id of the radio button is the value? or is the value of the radio button the value?)
Sorry, not really following. Is the selectedValue, in terms of the function updateScore, not the id of the chosen radio button and the value the actual achieved value?
try logging the two values. Which one is a number?
Ahh, I get you - that is helpful but what then am I trying to capture to identify the correct radio button. I thought it was id.
not sure what you meant when you said “the correct radio button”. I think this step is just asking you to find out which button is selected and then act based on that?
Absolutely but the id is telling me which button is selected and the value is telling me the score - I’m not sure why when passed to the updateScore function the totalScore isn’t being updated
Did you change your code (the 2 lines I mentioned above)?
It should fix the issue if you have.
The code looks like this at the moment. I just logged the values:
keepScoreBtn.addEventListener(“click”, ()=>{
let selectedValue;
let achieved;
for (const radioButton of scoreInputs){
if(radioButton.checked){
selectedValue = radioButton.id;
achieved = radioButton.value;
console.log(selectedValue);
console.log(achieved);
break;
}
}
if (selectedValue){
rolls = 0;
round++;
updateScore(selectedValue, achieved);
updateStats();
resetRadioOptions();
} else{
alert(“Select an Option”);
}
})
You have to switch these around.
So stupid!!! Thanks a lot, makes more sense now. I feel like an idiot!
No worries. Just as fyi, you should pick the post that helped you solve the problem to mark as the solution and not your own post generally unless your own post was the one that helped you. (People use the solution post as a way to tell what to read first)