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

Tell us what’s happening:

I need help checking my code. The backslash generates an error, therefore I cannot proceed. Maybe it’s a bug?

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) {
    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;
  }
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36

Challenge Information:

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

\n is a String so it has to be put inside a double quote: "\n"

Take a look at the code on line 172 as a reference:

  text.innerText = "You picked " + guess + ". Here are the random numbers:\n";

You have to put + before "\n".

Also, the parentheses around numbers[i] is not necessary.

But if you want to use string interpolation here then check this out for the correct syntax:

Thank you so much! It worked.

1 Like

The escape sequence (\n) should be a part of a string, just like how you did it a few lines earlier. You’ll need to concatenate a string to numbers[i] with the \n escape sequence. You’re missing an addition sign and some quotes.