What should max be initialized to? I’ve been trying to work it out, but have had no luck.
NUMBER_OF_INPUTS = 5;
var i;
var max;
var userInput; // Input from user
max = ???? ;
for(i=0; i<NUMBER_OF_INPUTS; i++)
{ userInput = parseInt(prompt('Enter input: '));
if (userInput > max)
max = userInput;
}
alert('Max: ' + max);
Use the Javascript
Number.NEGATIVE_INFINITYconstant. That way any user input will be bigger than what the variable is initialized to sinceNEGATIVE_INIFINTYis smaller than all other numbers that JS can represent.