This forum is now read-only. Please use our new forums! Go to forums
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
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.
Popular free courses
- Course
Learn SQL
Learn to communicate with databases using SQL, the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency