Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NAN

Status
Not open for further replies.

edwardglass57

Programmer
Mar 5, 2010
5
US
I will admit, I am an idiot.
I am getting NAN.
Code:
<script type="text/javascript">
    
    var num1;
    var num2;
    var num3;
    var ave_num=Math.round((num1 + num2 + num3) / 3);
    
    
//follow prompts to enter numbers and print average

    </script>
 
Why would you expect anything different when num1, num2, and num3 are all undefined.

Perhaps if you actually stored some numbers in them, you'd see a number as a result.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Thats why i added that those variables will be assigned vales via user input, through prompts, then return the average
 
Upon entering numbers for each prompt, it is the average that is getting me NAN
 
Hi

edwardglass57 said:
will be assigned vales via user input, through prompts
Have you checked what is returned by [tt]window.prompt()[/tt] ?
JavaScript:
[COLOR=darkgoldenrod]alert[/color][teal]([/teal][b]typeof[/b] window[teal].[/teal][COLOR=darkgoldenrod]prompt[/color][teal]([/teal][green][i]'gimme number'[/i][/green][teal]))[/teal]
Well, it is string. So parse it into numeric :
JavaScript:
[b]var[/b] num1[teal]=[/teal][COLOR=darkgoldenrod]parseInt[/color][teal]([/teal]window[teal].[/teal][COLOR=darkgoldenrod]prompt[/color][teal]([/teal][green][i]'gimme number'[/i][/green][teal]),[/teal][purple]10[/purple][teal])[/teal]

Feherke.
 
Yes, it works fine. I was simply asking if something is wrong with my average calculation. Sorry for the confusion
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top