+ 1

Javascript - Array question!!!

This code is in the book Head Frist. 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, 100, 18, 41, 53, 55, 61, 51, 44]; var lowScore = 0; var output; for (var i = 0; i < scores.length; i++) { output = "Bubble solution #" + i + " score: " + scores[i]; console.log(output); if (scores[i] > highScore) { highScore = scores[i]; } } console.log("Bubbles tests: " + scores.length); console.log("Highest bubble score: " + highScore); The out output for: console.log("Highest bubble score: " + highScore); is 69 and i dont know how could Javascript do it? // this section i don't know how if (scores[i] > highScore) { highScore = scores[i]; } Can you explain it for me, how could it could 69 as highest value, thank you.

20th Dec 2017, 4:53 PM
Anh Khoa Ton That
Anh Khoa Ton That - avatar
2 Answers
+ 3
If you look, after the 60 (first value), all values are less than it. The number greather than 60 (in order of scores) is 69, so you can think: My highscore has been actualized one time. (Or maybe, since the first value my highscore was never 60) This is my hint for you :)
20th Dec 2017, 5:09 PM
SebastiĂĄn Zapata
SebastiĂĄn Zapata - avatar
+ 1
Thank you for you answer, this is what i am looking for. I will think more about it. Wish you a Merry Christmas ^^
20th Dec 2017, 5:36 PM
Anh Khoa Ton That
Anh Khoa Ton That - avatar