Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-26-2013, 03:18 AM   PM User | #1
Kamma1124
New to the CF scene

 
Join Date: Feb 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Kamma1124 is an unknown quantity at this point
Prompted name document.writes as NaN

Hello everyone, very sorry upfront for the poor code. I need the script to spit out the person name not NaN. Basically what is happening is the script asks for a number and your name. The program is supposed to spit out your commission rate and your name. The script will spit out the commission rate just fine but the name shows up as NaN. please explain what I am doing wrong so that I may learn. Thank you.
Code:
<html>
<head>
<title>Patrick  - assignment03 - Exercise 2<</title>
</head>
<body bgcolor="DeepSkyBlue" text="wheat">
<script language="JavaScript" type="text/javascript">
alert("Welcome to Commission Calculator")	
	var num1 = prompt("Please enter your Total Sales Amount: ", "" );
	var name= prompt("Please enter your Name: ", "" );
document.write("===== Sales Commission Script ======", "<br>")
document.write("====== by Patrick  ===========", "<br>")
	if (num1 <= 9999)
document.write( +name+ " Your commission is " , (num1) * .02, "<br>")
	else if (num1 >= 10000)
document.write( +name+ " Your commission is $" , (num1) * .05 + 200, "<br>")
</script>
</body>
</html>

Last edited by Kamma1124; 02-26-2013 at 03:36 AM..
Kamma1124 is offline   Reply With Quote
Old 02-26-2013, 03:55 AM   PM User | #2
Kamma1124
New to the CF scene

 
Join Date: Feb 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Kamma1124 is an unknown quantity at this point
I guess I figured it out because I got my script to work. If anyone does look at this post at all. Can someone please chime in and let me know if they know of any good sources to read that could make things like this easier for me. It would be very greatly appreciated.

Code:
<html>
<head>
<title>Patrick - assignment03 - Exercise 2<</title>
</head>
<body bgcolor="DeepSkyBlue" text="wheat">
<script language="JavaScript" type="text/javascript">
alert("Welcome to Commission Caculator")	
	var num1 = prompt("Please enter your Total Sales Amount: ", "" );
	var name = prompt("Please enter your Name: ", "" );
	
document.write("===== Sales Commission Script ======", "<br>")
document.write("====== by Patrick ===========", "<br>")
	if (num1 <= 9999) 
	{
document.write( name, " Your commission is " , (num1) * .02, "<br>")
	}
	else if (num1 >= 10000)
	{
document.write( name, " Your commission is $" , (num1) * .05 + 200, "<br>")
	}
</script>
</body>
</html>
Kamma1124 is offline   Reply With Quote
Old 02-26-2013, 06:13 AM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
The first thing you need to do is to forget almost everything you have in your code.

document.write is completely obsolete and should no longer be used.

prompt and alert should only be used for debugging and should be removed before you upload a scrip to the web.

I have a few hundred example scripts on javascriptexample.net that start with some for beginners to learn the basics.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:33 AM.


Advertisement
Log in to turn off these ads.