Review Algorithmic Thinking by Building a Dice Game - Step 9

Tell us what’s happening:

I don’t understand why both the conversion to Int and the sum aren’t considered correct to pass the test.
Errors in console:
2. Your updateScore function should convert string value to integer and add the value to the total score.
3. Your updateScore function should add the value of the first parameter to the total score.

‘’’
const updateScore = (value, id) => {
const valueNum = parseInt(value || 0);
let currentScore = parseInt(totalScoreElement.value || 0);
currentScore += valueNum;
totalScoreElement.textContent = currentScore;
scoreHistory.innerHTML += <li>${id} : ${value}</li>;
}
‘’’

Your code so far

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

/* file: styles.css */

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

const updateScore = (value, id) => {
  const valueNum = parseInt(value || 0); 
  let currentScore = parseInt(totalScoreElement.value || 0);
  currentScore += valueNum;
  totalScoreElement.textContent = currentScore;
  scoreHistory.innerHTML += `<li>${id} : ${value}</li>`;
}

// 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/109.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 9

This function can be achieved with just three lines of code:

  1. Add the user selected value to the total score (for which you have a global variable).
  2. Update the totalScoreElement with the updated score.
  3. Add a li element to the scoreHistory element, to show the score achieved for this round.
2 Likes

Passed. Thanks a lot for your suggestions!

1 Like