Lesson 8: Console logs an extra "Rock wins." every time. What's wrong?


Here's my code. Got me past the lesson, but there's clearly something wrong, as every time I run it the console logs an extra "Rock wins" below the computer's choice and the actual outcome of the game.

Can't figure out where I've gone wrong. Can someone please explain? Thanks!

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) {
console.log("The result is a tie!");
else if (choice1 === "rock") {
if(choice2 === "scissors")
console.log("Rock wins.");
else if(choice2 === "paper")
console.log("Paper wins.");
else if(choice2 === "rock")
console.log("The result is a tie!")
else if (choice1 === "paper") {
if (choice2 === "rock") console.log("Paper wins.");
else console.log("Scissors wins.");
else if (choice1 === "scissors") {
if (choice2 === "paper") console.log("Scissors wins.");
else console.log("Rock wins.");


You could add some prints that let you know which values are being compared and why it decides to take the path it does.

You can make those prints explain to you in detail how it comes up with its decision. It should then be easy to tell where it goes wrong.