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

Tell us what’s happening:

Hello everyone kindly guide me on this challenge. The instruction is below;

Inside your while loop, push a random number between 0 and 10 to the end of the numbers array. You can create this random number with Math.floor(Math.random() * 11) .

please how do I use push method to add random number?

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) {
Math.floor(Math.random()* 11);
  }
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15

Challenge Information:

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

You need to add the Math.floor method within numbers.push() method parentheses.
@Answer_Alyosha

Thanks for your response. how do I use the push method?

function pick(guess) {
  const numbers = [];
  while (numbers.length < 10) {
push(Math.floor(Math.random() * 11));
  }
}

You call it on the array.

You used it previously in Step 90


1 Like

Thanks for your guidance. what you mean array?

function pick(guess) {
  const numbers = [];
  while (numbers.length < 10) {
random.push(Math.floor(Math.random() * 11));
  }
}

this is an array

I think what would help would be to go through the basic JS section from the legacy curriculum. It has smaller exercises for stuff like arrays.

Then you can revisit this project :+1:

The curriculum is currently going through a lot of updates to make it more beginner friendly. But in the mean time, going through the basic JS section from the old curriculum will help fill in the gaps you are having in the understanding for the JS basics.

Hope that helps

Thanks for this; really and truly appreciate.

1 Like