Learn Basic JavaScript by Building a Role Playing Game - Step 162

Tell us what’s happening:

As I understand the problem, I am to push the results of the math problem to the end of the array. I have 10 numbers that are produced at random and if the number picked happens to show up in the array, then you get a message stating you have guessed correctly or vice versa.

Your code so far

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

/* file: styles.css */

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

function pick(guess) {
  const numbers = [];
  while (numbers.length < 10) {
    const randomNumber = Math.floor(Math.random() * 11);
    numbers.push(randomNumber);
  }
 console.log(numbers);
  if (numbers.includes(guess)) {
    console.log(`Your guess ${guess} was **correct**!`);
  } else {
    console.log(`Your guess ${guess} was **incorrect**.`)
  }
}
pick(1)

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

Challenge Information:

Learn Basic JavaScript by Building a Role Playing Game - Step 162

Where does this const randomNumber come from? It is unexpected from the point of validation.
Take what you were given: Math.floor(Math.random() * 11), and pass it to numbers.push() as an argument.

1 Like