+ 6
Help me please with this piece of code
I tried to create a simple function finding the largest number in an array, but it doesn't work. Alert displays "0" intead of "34" var array = [1, 34, 5, 2, 32, 1]; var x = max(array); alert(x); function max(array){ var maxNum = 0; var i; for(i = 0; i<array.length; i++){ if(array[i]< maxNum){ maxNum = array[i]; } } return maxNum; }
3 Respostas