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

Tell us what’s happening:

I tried solving this very issue for over one week now. And I searched for solutions, but could not find it.

I need a guide line or link I can learn about loops properly before I continue with the exercise.

Honestly,

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) {
    let randomNumber = Math.floor(Math.random() * 11);
    numbers.push(randomNumber);
  }
}

// User Editable Region

Your browser information:

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

Challenge Information:

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

Hi everyone!

Please I have been on this very challenge over a week and yet to pass. Can anyone help me out or give a guide line?

my code below:

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

Hello,

your answer is not wrong but lesson give this after your answer;

You should push the result of Math.floor(Math.random() * 11) to the end of the numbers array.

This means that the lesson suggests performing this action without creating a new variable. You can directly generate and push a random number using Math.random() and Math.floor() inside the push function.

Also, a little humble advice: try to complete a lesson in one go. Taking breaks between lessons can cause you to forget the context or meaning of functions or code blocks. When I was learning, I always challenged myself to finish a lesson without interruptions, except for little necessary breaks, of course! :blush:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.