Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Level 6 lesson 5

Question:->
let x = 'I love 'Chocolate'\'Butterscotch' ice cream.';

// log the variable
console.log();

----------------------------------------------------------
//I am trying to submit below code. But it shows me (You missed to escape some special// //character. Please Check again.

let x = 'I love \'Chocolate\'\'Butterscotch\' ice cream.';

// log the variable
console.log(x);
by

2 Answers

kshitijrana14
Try this one

let x = 'I love \'Chocolate\'\\\'Butterscotch\' ice cream.';

// log the variable
console.log(x);
iamabhishek
The answer mentioned above is correct, just explaining it, because a lot of users get stuck on this lesson:

The expected outcome for this exercise is: I love 'Chocolate'\'Butterscotch' ice cream.

In between the words Chocolate and Butterscotch, we have an ending single quote, then a backslash, and then an opening single quote. All these three needs to be escaped.

Hence it becomes \' to escape the opening single quote, then \\ to escape backslash and at last \' to escape the opening single quote. Hence it becomes \'\\\' between the words Chocolate and Butterscotch.

 let x = 'I love \'Chocolate\'\\\'Butterscotch\' ice cream.';

// log the variable
console.log(x);


Hope it helps.

Login / Signup to Answer the Question.