0

I was following a JavaScript course. I needed to make a quiz. But I didn't understand something that was in de code. Why should the second time needs \n\ Red/Green\n\ Teal\n\ Yellow\n\

And not only \n?

var questions =[
  {
    prompt: "What color are apples?\n(a) Red/Green\n\
    (b) Purple\n(c) Orange",
    answer: "a"
  },
  {
    prompt: "What color are Bananas?\n(a) Teal\n\
    (b) Magenta\n(c) Yellow",
    answer: "c"
  },
  {
    prompt: "What color are strawberries?\n(a) Yellow\n\
    (b) Red\n(c) Blue",
    answer: "b"
  }
]

Thanks

Bennpoes
  • 13
  • 4
  • 1
    There is no regex in your question. – VLAZ Aug 15 '21 at 12:35
  • Regular expressions are delimited with `/`, not ```\```. What you're seeing there are multiline strings. The ```\``` at the end escapes the newline (because newlines aren't valid in string literals) allowing the string literal to continue on the next line. (In modern code, they probably would have used a template literal instead, since those can contain unescaped newlines and untagged template literals create strings.) – T.J. Crowder Aug 15 '21 at 12:37
  • No, it isn't. `\n` is a newline escape sequence. So the ```\n\``` you see at the end is a newline (`\n`) followed by a ```\``` escaping the actual literal newline that follows it in the source code (resulting in two newlines in the string). – T.J. Crowder Aug 15 '21 at 12:39
  • 1
    Thank you very much for answering my question! It helped me alot! – Bennpoes Aug 15 '21 at 12:46

0 Answers0