+ 1

When adding a string in javascript how can i take space between them?

//please complete this var myAge = prompt(); var isAdult = (myAge > 18)? "Too young" : "Old enough"; alert ("You are" + isAdult); //the answer comes when I given the value of 42, gives (You areOld enough) //I need a space between the word 'are' and 'Old' <!--please help me-->

30th Nov 2020, 8:07 AM
Thariq Imran
Thariq Imran - avatar
5 Antworten
+ 5
it is so simple, write: "you are " give a space at the end. another way, use `` (backticks) instead of quotes and you can insert variables within the string using `you are ${isAdult}`
30th Nov 2020, 8:10 AM
maf
maf - avatar
+ 1
or you can use: "Hello" + " " + "World"
30th Nov 2020, 8:57 AM
Artur
Artur - avatar
+ 1
Ok this time I need to get written in a new line,(by using document.write) that means I have to start my JavaScript code is second line.
30th Nov 2020, 9:01 AM
Thariq Imran
Thariq Imran - avatar
+ 1
'hello \n world'
30th Nov 2020, 9:31 AM
Artur
Artur - avatar
+ 1
Or with backtickets: `hello world`
30th Nov 2020, 9:32 AM
Artur
Artur - avatar