0

My main problem is with adding space in a JavaScript code.

how can I add space to the output of this code? function bestFiends(name1,name2,name3) { alert("The following, "+ name1 + name2 + name3+" are your bestfriends"); } name1=prompt("1rst name"); name2=prompt("2nd name"); name3=prompt("3rd name"); bestFiends(name1,name2,name3);

31st Mar 2020, 9:06 AM
Kevin Muriuki
Kevin Muriuki - avatar
3 odpowiedzi
+ 2
Consider that when you want to add a text or space you write on "" and when you want to add a variable to a text you need to separate it with + this is called concatenation Example : var a = awesome; alert("Learning at Sololearn is "+ a + " and this make me happy"); Output : Learning at Sololearn is awesome and this make me happy
31st Mar 2020, 9:14 AM
C0MM1T
C0MM1T - avatar
0
Thank you so much, I appreciate your answers.
31st Mar 2020, 9:29 AM
Kevin Muriuki
Kevin Muriuki - avatar
0
@Mirielle how exactly are you supposed to apply, because it is displaying an error? alert("The following, "+ ${name1},+ ${name2},+ ${name3} + "are your bestfriends");
31st Mar 2020, 9:40 AM
Kevin Muriuki
Kevin Muriuki - avatar