9. Next Step


#1



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

I was trying to do instruction 1 and 3, typed the code but nothing seems to work. Also, with the "Return" instead of "console.log". the result of the game doesn't send to console. Can someone please explain the "return" in more depth, and how does it defer from console.log?

var userChoice = prompt("Do you choose rock, paper or scissors?");
if (userChoice != "paper" || "scissors" || "rock") {
    console.log("Word you entered is invalid. Please enter one of the three words.")
}
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!";
        console.log("Let try again")
        
        }
    
    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"}
    }
    compare(userChoice, computerChoice)
}


#2

@betaslayer94396,
You are placing the call to the compare() function
within it's definition itself.......

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

  • the execution of the compare function _(keeping in mind that the return statement is used )