Review Algorithmic Thinking by Building a Dice Game - Step 10

Tell us what’s happening:

i have managed the checked attribute but now i dont understand about the value and id , and how to update score i totalscore element

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region
// here is code for this current problem(below this comment)
 keepScoreBtn.addEventListener("click",()=>{ 
   /* checked,capture value and attribute
   update score'
   reset radio options
   record in score history
   
   */

for(i = 0; i < scoreInputs.length; i++) {
  const ele =  scoreInputs;
  if (ele[i].checked){
    totalScoreElement.textContent =+ updateScore ();
  resetRadioOptions();
  scoreHistory.innerHTML += `<li>${value} : ${id}</li>`;


    }
    else{
      alert
    }


  };
 })
 //alert();

// 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/138.0.0.0 Safari/537.36 Edg/138.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 10

can you describe what the code should do line by line?

this is my current code: for(i = 0; i < scoreInputs.length; i++) {

const input = scoreInputs[i].value;

if (input.disbled = false){

totalScoreElement.textContent = updateScore();

resetRadioOptions();

scoreHistory.innerHTML += `

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

    the for loop goes through the radio options,then if clicked (disabled false) totalscore element updates toslscore the radiooptions is reset and score history uodated,i think

    1 Like

    still working on the score

    1 Like

    you keep doing this, do you see an error in the console? maybe when you click the button?

    1 Like

    find which radio option is checked

    Please focus on this bit in the instructions first. How can you determine which radio button is checked?

    i think its score options

    What is score options? I don’t see any variable or function or anything with that name?

    There is a div in the HTML with an id of score-options and inside that div, there are several radio buttons named score-options, but can you say how to determine which of those radio buttons has been checked?

    i can use score Input[i]. checked

    That’s close. Look again at the HTML entity references you created at the top of your script file. The reference in your code must be exact.

    Can you show the line of code for that reference?

    at the top of my script file i see this:const scoreInputs = document.querySelectorAll(“#score-options input”);

    Yes. So, based on that reference, how would you write the code to determine which of the radio buttons has been checked?

    You can use what you wrote earlier inside your loop with the correct reference this time:

    what about the totalscoreelement which needs to be updated

    Let’s get the checked radio button handled first before we move forward. You still have some work to do there. For example, look at the following line:

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

    Look up an example of a for loop. You are missing something. What do we need to do with variables before we can use them?

    Also, why do you need to create a variable ele?

    When you’re ready, show your code through the if statement. Remove all the code you wrote after the if statement.

    this is my current code : let i= options

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

    if (scoreInputs.checked){

     updateScore (value,id);
    

    resetRadioOptions();

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

    }
    
    else{
    
      alert('please choose an option');
    
    }
    

    first we declare it or assign it to aname :let i = options

    What’s this for? What is options?

    The syntax of your for loop is more incorrect now than it was when you first wrote it. Did you look up an example of the for loop syntax?

    scoreInputs is what type of data construct? How can you determine a checked state for the data construct you have written? Remember, you are inside a loop here and you are trying to determine which, if any, radio button was checked. That is all you should be doing inside the loop.

    Good that you are now passing in values for updateScore parameters, but where is value and id coming from? There are no variables in this block of code called value or id. And when we call a function there is no space between the function name and the parenthesis.

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

    if (scoreInputs.value){

    here is my code i have removed everthing apart from loop an if statement

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

    Please take a look at this from W3 Schools for examples of how to write a for loop:

    JavaScript for Loop

    Good that you are now declaring i correctly in the loop, but your condition is trying to get the length of scoreInputs at index i. What do you really want your condition to be the length of?