java script assignment

Hello

I am new to Javascript and trying to write this script that prompts a user for first and last name and then greets them. I have tried this and I am not sure if it is the best way to do it. It seems to work but it does not space the name. Any help would be appreciated. Thanks!




Home Page


var who1=prompt("What is your first name?");
var who2=prompt("What is your last name?");

function greeting(who1,who2){
answer = who1+who2;
return answer;
}






document.write("Welcome to my site " +greeting(who1,who2));




Comments

  • If you want space in between the first and last name, add it:

    [code]
    answer = who1+' '+who2;
    [/code]
  • If you want space in between the first and last name, add it:

    [code]
    answer = who1+' '+who2;
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion