Javascript concatenation problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Javascript concatenation problem

I have write a code like this: var a=prompt("enter a number",""); var b=Math.sqrt(a); console.log("The sqrt of"+ a+" is"+ b); Input:9 Output: The sqrt of9 is3 why there are no space beetween "of and 9"

30th Dec 2017, 9:12 PM
Abdullah Shaleh
Abdullah Shaleh - avatar
3 Answers
+ 6
You have to put the space inside of the string: "The sqrt of "+a+" is "+b
30th Dec 2017, 9:26 PM
Dapper Mink
Dapper Mink - avatar
+ 5
You are forgetting to put your spaces beside your string before concatenation.. Just a little elaboration on what the person above me has said.. You have to insert your spaces for them to show
30th Dec 2017, 11:54 PM
Promise Ihunna
Promise Ihunna - avatar
+ 3
change your console.log to: console.log("The sqrt of " + a + " is " + b); If you want there to be a space you need to put it there. When you use concatenation, strings are placed directly to the end of the previous string, no other character(s) are placed between them unless you deliberately concatenate them or modify the previous string prior to appending the next string.
30th Dec 2017, 9:32 PM
ChaoticDawg
ChaoticDawg - avatar