Basic JavaScript - Escape Sequences in Strings

Tell us what’s happening: KEEPS GIVING ME AN ERROR
I cannot move forward with the lesson, went to the video “Help” and as well this frum and latest update is August 2019. Changed even the var to const and still same issues, no variation of solution works

Your code so far

var myStr=‘FirstLine\n\t\\\SecondLine\\n\ThirdLine’; // Change this line

const myStr=‘FirstLine\n\t\\\SecondLine\\n\ThirdLine’; // Change this line

var myStr=\t‘FirstLine\n\SecondLine\\rThirdLine’; // Change this line

Your browser information:

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

Challenge: Basic JavaScript - Escape Sequences in Strings

Link to the challenge:

Definitely don’t change const to var. That will most likely cause the tests to fail.

const myStr=‘FirstLine\n\t\\\SecondLine\\n\ThirdLine’;

This one is pretty close. You’ve got a few too many back slashes though. Actually, I only needed to remove one back slash to get it to pass. Although there are other unnecessary back slashes that can be removed as well.

Also, make sure you are using plain old ascii single quotes. The code you pasted above appears to be using fancy quotes, which are causing a syntax error. As soon as I changed them to ascii quotes then the error disappeared.

1 Like

I feel like I am perhaps overlooking at the simplest answer. This is the only thing that is not checked off:

Please paste in your updated code so we can see what you have done.

To display your code in here you need to wrap it in triple back ticks. On a line by itself type three back ticks. Then on the first line below the three back ticks paste in your code. Then below your code on a new line type three more back ticks. The back tick on my keyboard is in the upper left just above the Tab key and below the Esc key. You may also be able to use Ctrl+e to automatically give you the triple back ticks while you are typing in the this editor and the cursor is on a line by itself. Alternatively, with the cursor on a line by itself, you can use the </> button above the editor to add the triple back ticks.

P.S. Don’t do pics of code. It’s not easy to test and it can be hard to read. Please paste in your code using the method above.

There is no need to put a single backlash before SecondLine and ThirdLine, also no need to use both the apostrophe ( single and double)

const myStr = "FirstLine\n\t\\SecondLine\n\ThirdLine"; // Change this line

So this worked :upside_down_face:, been trying to figure it out for over 3 days and finally just ended up writing it out letter/character by character and hitting “ctrl + enter” each letter lol :melting_face:

Thank you all! I sincerely appreciate it!!! <3

Great job. I will add that the last back slash before the capital T is not needed. I don’t think it’s doing any harm there and the tests certainly aren’t failing you for it. But it’s not doing anything either.

It seems like you’re having trouble with escape sequences in strings in JavaScript. Let’s take a closer look at the issues in your code.

First, it appears that you’re using the wrong type of quotes. In JavaScript, strings should be enclosed in single (’ ') or double (" ") quotes, but your code is using backticks (‘ ’) in some places. Replace those backticks with single or double quotes.

Next, ensure that you’re escaping the characters correctly. In the first line, you have unnecessary backslashes before ‘n’ and ‘t’. Remove those backslashes.

Here’s a corrected version of your code:

var myStr = 'FirstLine\n\t\\SecondLine\\n\\ThirdLine'; // Change this line

// Or using double quotes
// var myStr = "FirstLine\n\t\\SecondLine\\n\\ThirdLine"; 

// Note: Choose either single or double quotes consistently

// Remove the unnecessary backslashes in the following line
var myStr = '\tFirstLine\n\\SecondLine\\rThirdLine'; // Change this line

// Or using double quotes
// var myStr = "\tFirstLine\n\\SecondLine\\rThirdLine";

Make sure to pick either single or double quotes and be consistent throughout your code. Also, ensure that you’re escaping the characters correctly according to the challenge requirements.

Regarding the issue with your browser information, it doesn’t seem directly related to the code problem you’re facing. If you’re using a editing software for chromebook, make sure that your browser is up to date, and consider trying a different browser to see if that resolves the issue.

I hope this helps! If you have further questions or issues, feel free to ask.