Wednesday, 15 January 2014

javascript code for finding maximum value from an array -



javascript code for finding maximum value from an array -

i trying print out statement code wrote dont know why not printing anything.

var max = 0; var i; var array=new array [5]; i=prompt("enter 5 numbers find max"); i=parsefloat(i); for(i=0;i<array.length;i++){ if (array[i]>max) max=array[i];} alert("your highest number " + max ); document.write("max = " + max);

try out

var max = 0; var i; var array=[]; for(i=0;i<5;i++){ var number=prompt("enter 5 numbers find max"); number=parsefloat(number); if(number>max) max=number; // if need hold value array.push(number); } alert("your highest number " + max ); document.write("max = " + max);

javascript

No comments:

Post a Comment