Paper, Scissors, Rock. It works, but doesn't announce the winner


#1


https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/4?curriculum_id=506324b3a7dffd00020bf661


It works but doesn't announce the winner

e.g "I choose scissors" the response is "computer:paper" with no winner.
but it still says "Congratulations, Challenge Complete!"


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(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 "Paper wins";
}    
    else{
 return "Scissors wins";  
   }    
 } 
 else if (choice1 === "scissors"){
 
 if (choice2 === "paper"){
   return "Scissors wins";
 }
   
  else {
      return "Rock wins";
  }
 }  
}
compare(userChoice,computerChoice);


#2

you could add, you win or your lose, or change what is returned for example:

else if (choice1 === "rock"){
    
 if (choice2 === "scissors"){
        return "You win";
 }
   else {
       return "Paper wins, sorry you lost";
   }
}

the exercise build a basic game, you can now add your own features


#3

You should add a console.log when you call the compare function.


#4

the codecademy console will echo the last value, so i am not sure that is the problem.


#5

There is a semi-colon missing before the function call.


#6

hm... maybe you are right. maybe the function call should be wrapped in console.log, not all browsers might echo the last value. I thought the question was asked because the program doesn't give a clear winner (player or computer wins)


#7

If you try running the above code in a javascript interpreter like the one available in Chrome Developer Tools, it would output the value straightaway. For consistency, I prefer console.log for printing.