Michael Michael - 2 years ago 55
Javascript Question

How to make a space when concatenating strings

I have written some code that works fine but I am trying to make a space between the strings.

The code I have is:

<title> Concatenating Strings </title>
<script type = "text/javascript">
var greetingString = "Hello";
var myName = prompt ("Please enter your name","");
var concatString;
document.write(greetingString + "" + myName + "<br>");
concatString = greetingString + "" + myName;

At the moment the script shows HelloMichael, I am wanting it to show Hello Michael. Can someone please advise me on how I can do that?

Answer Source

To insert a space character, simply insert a space character. For example:

greetingString + " " + myName

There's no space in your current output, because "" doesn't have a space in it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download