This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Marc Ohlsson
over 8 years

what does unexpected EOF mean

var compare=function(choice1,choice2){
    if(choice1===choice2){
        return "The result is a tie!";
    }
    else if(choice1==="rock"){
        if(choice2 ==="scissors"){
            return"rock wins;}
        }
        else{
            return"paper wins";
        }
    }
    else if(choice1==="paper"){
        if(choice2==="rock")
            return"rock wins";
    }
    else{
        return"scissor wins";
    }
}

Edit: code formatted by haxor789. You can do this yourself by using the { } button or CTRL+K

Answer 53bd0b81631fe9a13200188c

0 votes

Permalink

EOF normally means End Of File. probably this never ending string is part of the problem:

 return"rock wins;}

Also this else:

else if(choice1==="paper"){
    if(choice2==="rock")
        return"rock wins";
}
else{
    return"scissor wins";
}

is one the same level as the else ifs although it should be part of the last else if e.g.

else if(choice1==="paper"){
    if(choice2==="rock")
        return"rock wins";
    else{
        return"scissor wins";
    }
}

As it is the last statement in this comparision their might not be a difference but if it is not intended it can lead to unexpected behaviour without throwing errors.

points
Submitted by haxor789
over 8 years