+ 3
Could someone please tell me why this is code didn't work? (no new line in the code playground)
var sayHello = 'Hello \n \r world! \'I am a JavaScript programmer.\' '; document.write(sayHello);
9 Respostas
+ 4
I think it would work if you replace the outer ' ' with " ".
+ 4
I don't think so, try using console.log to see if it's going wrong at the string or at the document.write()
+ 3
It works fine for me, even with the ' '.
+ 3
console.log() is a function, if you use it the message inside the () will appear at the bottom of your screen (the console)
+ 2
Thank you guys for answer my question. the code was an example from sololearn. but even after I change the outter quote to " , it still doesn't work. any idea?
+ 1
I think @The Coding Sloth answered already, you can't nest single quotes within single quotes and double quotes in double quotes unless you escape the internals.
Best single quotes outside double quotes inside and vice versa.
+ 1
I'm using Samsung S6, maybe that makes a difference?
+ 1
How do I find console.log in sololearn code playground?
+ 1
@the coding slotb, console.log() shows the new line correctly but document.write() doesn't start a new line. strange.
thank you for showing me the other way to print