Unexpected End of Input?


#1

I'm not sure if I'm doing my code right, can anyone help me please? Thank you.

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
var compare = function(choice1, choice2){
if( userChoice === computerChoice ){
return "The result is a tie!";
} else if( userChoice === "rock" ){
if( computerChoice === "scissors" ){
return "rock wins";
}else{
return "paper wins";
}
} else if( userChoice === "paper" ){
if( computerChoice === "rock" ){
return "paper wins";
}else{
return "scissors wins";
}
} else if( userChoice === "scissors" ){
if( computerChoice === "paper" ){
return "scissors wins";
}else{
return "rock wins";
}
};
};

function compare(userChoice, computerChoice)

#2

@suzukiyachiyama,

If you want to call the compare function
you will have to use

console.log( compare(userChoice,computerChoice) );

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on:

  • the creation of the compare function
  • the truth-table
  • the build of the IF ELSE-IF statement structure as part of the compare FUNCTION-BODY
  • the execution of the compare function (keeping in mind that the return statement is used )

and read about named-function's
http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname?rq=1