8.What if choice1 is "scissors".Please HELP!


#1

Please help me correct the code. I am lost ! Thank you !
here is what I did >>>

var userChoice = prompt("Do you choose rock, paper, or sissors?");
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 === "scissors") {
        if (choice2 === "rock") {
            return "rock wins";
        } else {
            return "scissors win";
        }
    } else {
        if (choice2 === "rock") {
            return "paper wins";
        } else {
            return "scissors win";
        };
    };

#2

@courseslayer93067 Just add a curly brace here:


#3

i agree with your answer, but i want to explain it.

You need one more closing curly bracket (}) to close your function:

var compare = function(choice1, choice2) {

the opening bracket of your function doesn't have a matching closing curly bracket, like steven.copeland mentions


#4

Okay, where exactly I should close it? Because I tried but it's still not working...


#5

at the very end? since all the comparison should be inside the function, @steven.copeland told you where to close it, if it is still not working, post an updated version of your code


#6

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"
        }
};

#7

I made it all over again, and tried to correct how you said. but it still does not work . Thank you for your help


#8

how did you manage to make it worse, this was the code you had:

var userChoice = prompt("Do you choose rock, paper, or sissors?");
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 === "scissors") {
        if (choice2 === "rock") {
            return "rock wins";
        } else {
            return "scissors win";
        }
    } else {
        if (choice2 === "rock") {
            return "paper wins";
        } else {
            return "scissors win";
        };
    };

all you have to do, is to add an additional } at the end of your code to close the function

And the function call is missing, you will have to add it, after you closed your function


#9

This is what computer says. Oops, try again. There was a problem with your syntax.... I hope I didn't peeved you with my exercise.

var userChoice = prompt("Do you choose rock, paper, or sissors?");
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 === "scissors") {
        if (choice2 === "rock") {
            return "rock wins";
        } else {
            return "scissors win";
        }
    } else {
        if (choice2 === "rock") {
            return "paper wins";
        } else {
            return "scissors win";
        };
    };
    console.log("userChoice");
    console.log("computerChoice");

#10

At first you didn't do what @stetim94 told you and i think you don't now how to call a function.

all you have to do, is to add an additional } at the end of your code to close the function.

so add it

} else {
            return "scissors win";
        };
    };

   add it here }.

now u should have three } bracket after return "scissors win";

then call the function.check it how to call a function
https://discuss.codecademy.com/t/i-do-not-understand-how-to-call-a-function-what-am-i-doing-wrong/37701/7?u=rcodeman


#11

4 posts were split to a new topic: 8. what if choice1 is scissors