If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

I think the point of the exercise is to learn how to loop over an array and compare values.

Using Math.max could get you what you want, however this is the incorrect way to use it. Instead, use it this way:

Code:

var maxValue = Math.max.apply(Math, numbersArray);

I suspect this isn't what the class exercise is aiming for. Instead, you want to loop over all the numbers in the array. You need to keep track of which number is currently largest in another variable. There is no need to Math.max().

So using the comments I posted already you could walk through each iteration of code something like:

Code:

var numbersArray = [8, 43, 23, 54, 9];
var maximum = 0; //we start with a maximum of zero since all the numbers in the array are positive numbers greater than 0
for (var i = 0; i < numbersArray.length; i++) {
//you need to compare the current number from the array to your current maximum
//for that you need a conditional statement
//if the current number numbersArray[i] is greater than maximum we have a new maximum
//in the first iteration numbersArray[i] will be 8 and maximum will be 0 because we haven't changed it
}

/* the if statments says that if the numbers in the array are larger than the established maximum,
then the next highest number will be the new maximum */
if (numbersArray[i] > maximum) { maximum = numbersArray[i]; }
}

/* the if statments says that if the numbers in the array are larger than the established maximum,
then the next highest number will be the new maximum */
if (numbersArray[i] > maximum) { maximum = numbersArray[i]; }
}