What's wrong with my code?

Hi. I’m not sure whether it’s allowed to ask or not but I’m new here and I’m on my first problem in the Easy section and I’m still getting to grips with the site. So, I think I solved the first challenge (The Descent) but the console says:

Invalid command sent. It should be an integer from 0 to 7.

This is the algorithm I managed to come up with:

{quote]
// game loop
while (true) {
var arr = [];
for (let i = 0; i < 8; i++) {
const mountainH = parseInt(readline()); // represents the height of one mountain.
arr.push(mountainH);
}

// Write an action using console.log()
// To debug: console.error('Debug messages...');

var max = arr[0];
for (let i = 0; i < arr.length; i++) {
    if (arr[i] > max) {
        max = arr[i];
    }
}

console.log(max); // The index of the mountain to fire on.

}
[/quote]

2 posts were merged into an existing topic: The Descent - Puzzle discussion