I've got my whole thing working, but I just can't figure out why when I return "It's a tie" it has to be in parens without a ;, whereas "Rock wins" doesn't need parens but does need a ;


#1


var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < .34) {
    computerChoice = "rock";
} else if (computerChoice <= .67) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
} console.log("Computer:" + " " + computerChoice);

var compare = function(choice1, choice2) {
    if (choice1 === choice2) {
        return ("It's 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 === "rock") {
            return "Rock wins!";
        } else {
            return "Scissors wins!";
        }
    }
};

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


#2

it is not compulsory.you can write like

return "It's a tie" ; // without parenthesis


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.