Review Algorithmic Thinking by Building a Dice Game - Step 10

I thought if use length of it will include the other options hence it will loop through the other score options

It would if you were using it on scoreInputs. But you are trying to get the length of only one of the scoreInputs options by applying an index to it. That’s something you do inside the loop. scoreInputs has all the options; but inside the loop, scoreInputs[i] gets one of the options, depending on the value of i.

like this keepScoreBtn.addEventListener(“click”,() => {

for(let i = 0; i < scoreInputs.length; i++) {

if (scoreInputs[i].checked){

let selectedoption = null;

selectedoption = scoreInputs\[i\].checked(id, value);



break;

keepScoreBtn.addEventListener(“click”,() => {

for(let i = 0; i < scoreInputs.length; i++) {

if (scoreInputs[i].checked){

let selectedoption = null;

selectedoption = scoreInputs[i].checked(id, value);



break;

This part of your code is good!

But this is not correct syntax. You used scoreInputs[i] to find out if one of the score input options was checked, right? So now that you know it’s checked, you just need to get the value of that option and assign it to selectedOption. Please give that variable assignment another try.

for(let i = 0; i < scoreInputs.length; i++) {

let selectedoption = null;

selectedoption = scoreInputs[i].checked;





break; }

if (scoreInputs[i].checked){

updateScore ();

resetRadioOptions();

scoreHistory.innerHTML += `${value} : ${id}`;

When in your code do you want to store the value of the checked score input option?

How do we get the value of HTML elements?

Also, please consider the full stack developer curriculum. There are many supporting lectures with code examples and small 3-question quizzes to test yourself before you move on. Then after the lectures, you are introduced to step-by-step workshops and labs that are more up to date. I think you would like that curriculum better.

check this out: keepScoreBtn.addEventListener(“click”,() => {

let selectedoption = null;

for(let i = 0; i < scoreInputs.length; i++) {

selectedoption = scoreInputs[i].checked;







break; }

if (selectedoption){

 const selectedValue = selectedoption.value;

const id = selectedoption.id;

 updateScore (id, selectedValue);

  score += parseInt(selectedValue);

totalScoreElement.textContent = score;

resetRadioOptions();

scoreHistory.innerHTML += `<li>${id} : ${value}</li>`;

}

else if(selectedoption === null){

  alert('please select input ');

}

});

for(let i = 0; i < scoreInputs.length; i++) {
    selectedoption = scoreInputs[i].checked;
    break; 
}

Please explain what you think this is doing.

avtually i changed to: let selectedOption = null;

for(let i = 0; i < scoreInputs.length; i++) {

 if (scoreInputs[i].checked) {

   selectedOption = scoreInputs[i];

   break;

now this new code ALLOWS to loop more than once unlike my other code the one you were asking about. the new code loops at least 6 times then if takes the one of them that is checked from the loop then stores it in selectedoption then loops is broken

You figured it out. That’s great!

what confuses me is the part ofselectedvalue updatescore.

for example lets say the select option is three of a kind then the seleced value is three of a kind or?

thus in updatescore parse int should convert the three of kind to a number but how since its a string:if (selectedOption){

const selectedValue = selectedOption.value;

const id = selectedOption.id;

updateScore(selectedValue);

score += parseInt(selectedValue);

totalScoreElement.textContent = score;

resetRadioOptions();

scoreHistory.innerHTML += `

  • ${id} : ${selectedValue}
  • `;

    const updateScore = (selectedValue, achieved) => {
      score += parseInt(selectedValue);
      totalScoreElement.textContent = score;
      scoreHistory.innerHTML += `<li>${achieved} : ${selectedValue}</li>`;
    };
    

    Look at the updateScore() function you created earlier in this workshop. Aren’t you attempting to repeat what it’s already doing? And don’t forget to pass in both of its required parameters when you call it.