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

Tell us what’s happening:

I’m stuck on step 172 on the build a role playing game lesson. Even after finding someone with the same issue in the forums and searching else where I wasn’t able to find a solution or at least understand one.

After your for loop, add an if expression to check if the guess is in the numbers array. You can check if indexOf is not equal (!== ) to -1 .

Your code so far

function pick(guess) {
  let numbers = [];
  while (numbers.length < 10) {
    numbers.push(Math.floor(Math.random() * 11));
  }
  text.innerText = "You picked " + guess + ". Here are the random numbers:\n";
  for (let i = 0; i < 10; i++) {
    text.innerText += numbers[i] + "\n";
  }


/ PART IN QUESTION\
  if(numbers.indexOf(guess)) {}
}
/ PART IN QUESTION\

Your browser information:

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

Challenge Information:

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

You need to check that what indexOf returns is not -1

if (someArray.indexOf(someThingToCheckFor) !== -1)
1 Like