I have written some code that works fine but I am trying to make a space between the strings.
The code I have is:
<html>
<head>
<title> Concatenating Strings </title>
</head>
<body>
<script type = "text/javascript">
var greetingString = "Hello";
var myName = prompt ("Please enter your name","");
var concatString;
document.write(greetingString + "" + myName + "<br>");
concatString = greetingString + "" + myName;
document.write(concatString);
</script>
</body>
</html>
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?
I have written some code that works fine but I am trying to make a space between the strings.
The code I have is:
<html>
<head>
<title> Concatenating Strings </title>
</head>
<body>
<script type = "text/javascript">
var greetingString = "Hello";
var myName = prompt ("Please enter your name","");
var concatString;
document.write(greetingString + "" + myName + "<br>");
concatString = greetingString + "" + myName;
document.write(concatString);
</script>
</body>
</html>
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?
Share Improve this question asked May 13, 2016 at 17:45 MichaelMichael 351 silver badge5 bronze badges 2- If you want a space between the strings, concatenate them with a space. – ssube Commented May 13, 2016 at 17:48
- oh c'mon... talk about low value questions :/ – Nelson Teixeira Commented May 13, 2016 at 17:52
3 Answers
Reset to default 2To 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.
put a space between hello and michael like this:
concatString = greetingString + " " + myName; //notice the space in the string
concatString = greetingString + " " + myName;
Simply change your "" to " ", the second has a space in it.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745309163a4621897.html
评论列表(0条)