+ 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"
3 Answers
+ 6
You have to put the space inside of the string:
"The sqrt of "+a+" is "+b
+ 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
+ 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.