Review Algorithmic Thinking by Building a Dice Game - Step 10

Tell us what’s happening:

It’s 2 days I’m trying this, even with the help of google, the fcc forum and the AI. I don’t know how to pass the level.
Trying the game, it works as expected if I comment updateScore() inside the function, otherwise, NaN appears. Please help.

Your code so far

/* file: script.js */
// User Editable Region

keepScoreBtn.addEventListener("click", () => {
    let selectedOption = null;

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

    if (selectedOption === null) {
        alert('Please select an option or roll the dice');
        return;
    }
    //updateScore();
    resetRadioOptions();      
    totalScoreElement.textContent = parseInt(totalScoreElement.textContent || 0) + parseInt(selectedOption);
    scoreHistory.innerHTML += ` ${selectedOption}, `;
    console.log(totalScoreElement.textContent);
    console.log(scoreHistory.innerHTML);
    console.log(selectedOption);
});

// User Editable Region
/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 10

Reread the instructions carefully. You’re overlooking something there.

1 Like

Hi this is the updateScore function.

const updateScore = (selectedValue, achieved) => {
  score += parseInt(selectedValue);
  totalScoreElement.textContent = score;

  scoreHistory.innerHTML += `<li>${achieved} : ${selectedValue}</li>`;
};

I believe there’s something the updateScore function is after you aren’t providing.

2 Likes

When you’re stuck like this, sometimes it helps to just step through the instructions with comments, like this:

// find which radio option is checked
// capture its value
// capture its id
// if an option is selected
      // call function to update score
      // reset radio options
      // add value and id to score history
// else
    // display an alert to select an option

and then add your code.

Good luck!

1 Like

Thank you guys, I passed with comments/instructions method (thanks fcc4b6d10c4-b540-4e2!).
I already did yesterday what a2937 suggested, but I was always a step away from the solution.