Quotes error in console.log

Tell us what’s happening:
Why the console in freeCodeCamp shows the quotes here? please help me.

Your code so far

const myStr = "I am a \"double quoted\" string inside \"double quotes\"";

Your browser information:

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

Challenge: Escaping Literal Quotes in Strings

Link to the challenge:

Say we want to log a string: console.log("hi"). That logs hi but how do we log literally "hi"? Because the JS interpreter will use quotes to delimit where the string starts and end, but won’t display them.

Hence, it is need to tell the interpreter that those quotes are to be displayed, and not for defining a string type. That’s done with backslashes before the quote \".

It’s also worth notice that the \ has a special meaning. Try using \t, for example.
How would you display “hi”, then?

Yeah, the console output is odd on this one. It shows:

myStr = "I am a "double quoted" string inside "double quotes""

It is parroting back your code with the right half having the escape \s removed and surrounding quotes? Yeah, that looks odd to me.

It would be like the result of:

console.log("myStr = " + "\"" + myStr + "\""); 
// myStr = "I am a "double quoted" string inside "double quotes""

adding some extra stuff in there, to make it pretty. But it looks odd to me because it almost looks like code - something we don’t normally see in the console.

A more bare bones logging like:

// I am a "double quoted" string inside "double quotes"

I mean, there is nothing wrong with it, per se, but I could see how that phantom logging, in an odd format might confuse the uninitiated.

1 Like

the console output is odd here. I think there is a bug inside the testing module!

I see no reason to believe that there is a bug in the ‘testing module’. The solution above is not quite correct.

Okay then, can you please check that challenge?

What do you mean by ‘check that challenge’? The solution above is wrong. When you use the correct solution, you pass the challenge.

1 Like

I just want you to check that piece of challenge and you will find out what wrong ! just go to that link and do what it needs and then you will find out the console shows odd behave in this challenge

The console log has absolutely nothing to do with the ‘testing module’.

1 Like

Got that he is missing one period(.) at the very last and I was copy pasting his code thats why it shows wrong answer! thats my bad!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.