# if statements

• May 26, 2007, 03:25
calamine
if statements
What would be the proper syntax to find the lowest of 5 user input numbers using IF statements?
• May 26, 2007, 04:13
calamine
I used this syntax but the number3 is always identified as largest even when it is not.

//largest
if (number1 > number2 > number3)
largest = number1;
else if (number2 > number1 > number3)
largest = number2;
else
largest=number3
• May 26, 2007, 04:27
Kravvitz
You can't do it like that. You can only compare one item to another at a time. You can't compare 3 items to each other.

You can do the logical equivalent by using the and operator (&&) like this:
(the extra parentheses are optional here)
Code:

`if((number1 > number2) && (number1 > number3))`
• May 26, 2007, 04:36
mrhoo
largest= Math.max(number1 , number2 , number3)

or for an array of numbers-

var numberarray=[2,14,3,4,1,7]
var largest= Math.max.apply('',numberarray);
• May 26, 2007, 04:59
calamine
would this work for five numbers?
thanks for all the help!!!!!