Is the var highScore = 0
apart of the loop? Isn't scores[i]
always greater than 0
? I need someone to break down how the if statement is working, and I need to understand how highScore = scores[i]
is giving me back the highest number. This exercise was in a book I'm reading to learn JavaScript, and I just feel it's way over my head. Can anyone shed light? Thank you.
How is the if statement working in this code? How is highScore even relevant as a variable to be used in the if statement, if it's value is 0? It doesn't seem logical for it to suddenly output the value is the highest number in the array.
var scores = [60, 50, 60, 58, 54, 54, 58, 50, 52, 54, 48, 69, 34, 55, 51, 52, 44, 51, 69, 64, 66, 55, 52, 61, 46, 31, 57, 52, 44, 18, 41, 53, 55, 61, 51, 44];
var highScore = 0;
for (i = 0; i < scores.length; i++) {
output = "Bubble #: " + i + " scores: " + scores[i];
console.log(output);
if (scores[i] > highScore){
var highScore = scores[i];
}
}