Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
java script assignment Posted by jaynesmy on 6 Feb 2012 at 2:12 PM
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!


<html>
<head>
<title>Home Page</title>

<script type="text/javascript">
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;
}

</script>
</head>

<body>
<script type="text/javascript">
document.write("Welcome to my site " +greeting(who1,who2));
</script>

</body>
</html>
Report
Re: java script assignment Posted by Flakes on 9 Feb 2012 at 11:15 PM
If you want space in between the first and last name, add it:

answer = who1+' '+who2;
Report
Re: java script assignment Posted by Flakes on 9 Feb 2012 at 11:16 PM
If you want space in between the first and last name, add it:

answer = who1+' '+who2;



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.