8. What if choice1 is scissors?


#1

My Code work, but something is wrong. I can not finish the topic. Can someone help me?

This is wrong said the programm: Oops, try again. Your code returned 'rock wins' instead of 'undefined' when the inputs are scissors and paper

MY CODE:
var userChoice = prompt("Do you choose rock, paper or scissors?");
console.log ("User: " + userChoice);

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(userChoice, ComputerChoice) {
if (userChoice === computerChoice) {
return "The result is a tie!";
} else if (userChoice === "rock") {
if (computerChoice === "scissors") {
return "rock wins";
} else {
return "paper wins";
}
} else if (userChoice === "paper") {
if (computerChoice === "rock") {
return "paper wins";
} else {
return "scissors wins";
}
} else if (userChoice === "scissors") {
if (computerChoice === "paper") {
return "scissors wins";
} else {
return "rock wins";
}
}
};
compare (userChoice, computerChoice);


#2

While creating compare() function in this chapter, It was written in instructions..

It takes two parameters, choice1 and choice2.

here computerChoice is a number between 0-1(globally defined) .

How to fix current code?

replace
`userChoice` with `choice1`
`computerChoice`with`choice2`

in your compare() function!


#3

ok I understand, but the program give me the description, that I have to swap choice1 in userChoice and choice2 in computerChoise. So now I have to define a new var to change it back before I do the compare() function, right?


#4

at last line we call our function by putting these two variables in place of parameters choice1 and choice2.


#5

great. It works. Thanks for your help


#6

@greentreemee, sorry to divert the topic, just curious how you make that code blurry?

like a /spoiler tag? Was wondering where I can find these information. I'm very intrigued! Thanks! :smiley:


#7

Select the content that you want to blur ,then use this..

Check this article..


#8

@greentreemee, thanks for the direction! :smiley:


#9

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