Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Can't figure out what's wrong. Help with basic math calculations.

1. ## Can't figure out what's wrong. Help with basic math calculations.

I am making a simple javascript where I ask for three number inputs from the user. The script then returns sum, product, average, largest, and smallest.

The largest and smallest numbers are coming out, but not the arithmetic.

Hoping someone can tell me what is wrong.

Code:
```	<script type = "text/javascript">

<!--
var input_one;
var input_two;
var input_three;
var firstNumber;
var secondNumber;
var thirdNumber;
var largest;
var smallest;

input_one = window.prompt( "Please Type a Number" );
input_one = window.prompt( "And Another One" );
input_three = window.prompt( "Just One More" );

firstNumber = parseInt (input_one );
secondNumber = parseInt ( input_two );
thirdNumber = parseInt ( input_three );

largest = firstNumber;
smallest = firstNumber;

if (secondNumber > largest)
largest = secondNumber;

if (thirdNumber > largest)
largest = thirdNumber;

if (secondNumber < smallest)
smallest = secondNumber;

if (thirdNumber < smallest)
smallest = thirdNumber;

"Sum: " + ( firstNumber + secondNumber + thirdNumber ) + "\n" +
"Average: " + ( ( firstNumber + secondNumber + thirdNumber ) / 3 ) + "\n" +
"Product: " + ( firstNumber * secondNumber * thirdNumber) + "\n" +
"Largest: " + largest + "\n" +
"Smallest: " + smallest );
//-->

</script>

• Code:
```input_one = window.prompt( "Please Type a Number" );
input_one = window.prompt( "And Another One" );```
I don't know if you can blame this one on arithmetic

• Code:
```input_one = window.prompt( "Please Type a Number" );
input_one = window.prompt( "And Another One" );
input_three = window.prompt( "Just One More" );```
Took a few minutes to spot this Edit: xelawho got there before me..

• The <!-- and //--> comment (hiding) tags have not been necessary since IE3 (i.e. since September 1997). If you see these in some published script it is a warning that you are looking at ancient and perhaps unreliable code.

Although legal is is a bad idea to omit the braces around a one-line if statement. It is recommended that you place the opening brace following the function, if, else, for, while, do, switch, and try statements on the same line and not on the following line. Apart from that every Javascript statement should be followed by a semi-colon. It is quite possible to disregard this advice, but if you do one day it will rise up and bite you in the undercarriage.

•

#### Posting Permissions

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