Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •