Build scissors paper rock


#1

Can someon pls tell me what is wrong
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"
}
}
}
compare(userChoice,computerChoice)

Oops, try again.
Your code returned 'The result is a tie!' instead of 'undefined' when the inputs are scissors and rock


#2

You will have to use the comparison-operator ===
instead of you using the assignment-operator =.


#3

Hey,
just wanted to tell you, that this line of code has an error, because everytime a random number smaller than 0.67 comes up, it will return "paper", but it should return also "rock" when the number is smaller than 0.34.
I think the correct code in that "else if" statement should be (0.34 <= computerChoice <= 0.67)
Cheers


#4

I got prablems... what is wrong here?
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 win!";
}
else if (choice1 === "Scissors") {
if (choice2 === "Rock") {
return "Rock wins!";
}
else {
return "Paper wins!";
}
}


#5

@kobajagrande,
The =flow= of the IF ELSE-IF ELSE statement.

IF (condition < 0.34)=>true=> { code-block } =>exit
          |
        false
          v
ELSE IF (condition <=0.67)=>true=> { code-block }=>exit
          |
        false
          v
ELSE { code-block } =>exit

----------------------------------

(0.34 <= computerChoice <= 0.67)
should be written as
( 0.34 <= computerChoice && computerChoice <= 0.67)
In this comparison
you use the relational-operators greater-than > and less-equal-than <=
and you are using the logical-AND-operator &&
= https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators


#6

i tried that but it still said the same thing


#7

@theprotatogrammer
Please present your corrected code...


#8

dont worry its fixed now