Javascript While to be in a function ERROR


#1


Getting two ERRORS
Expected 'while' to be in a function.
Unexpected '>'.
and code does nothing so far for me .. hope somebody can help me thanks a lot :slight_smile:


var location1 = 3;
var location2 = 4;
var location3 = 5;

var guess;
var hits = 0;
var guesses = 0;

var isSunk = false;

while (isSunk == false) {
    guess = prompt("enter a number 0-6");

    if (guess < 0 || > 6) {
        alert("Please enter a valid cell number!");
    } else {
        guesses = guesses + 1;
    }
    if (guess == location1) {
        hits = hits + 1;
    } else if (guess == location2) {
        hits = hits + 1;
    } else if (guess == location3) {
        hits = hits + 1;
    }

}


#2

Deal with the error from the interpreter first. Read what it says, there's only one matching occurrence.


#3

Cant Figure it out myself another gibt :smile: ?


#4

Where do you have > in your code?
You can run it in another interpreter as well to get it pointed out for you, but with this code size and when there's only one of them, it makes no difference, you already have all the information from the error message that you did get.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.