Build "Rock, Paper, Scissors"


#1

What is wrong with my code?
var userChoice = prompt("Do you choose rock, paper or scissors")
var computerChoice =Math.random("Do you choose rock,paper or scissor")
console.log (computerChoice);
if (computerChoice <= 0.33){
return rock;
} else if(computerChoice = 0.34 && computerChoice <= 0.66){
return paper;
}else{(computerChoice = 0.67 && computerChoice <= 1)
return cut;
}
console.log(computerChoice);


#2

There is your problem:

var computerChoice =Math.random("Do you choose rock,paper or scissor")


#3

I corrected it but it still showing syntax error


#4

This line will also give you an error because an else statement doesn't take a condition.


#5

men your problem of sintax is that you pu :

return rock;

the correct one is

return "rock";


#6

Each time you make corrections in response to forum replies, please post your new code.


#7

var userChoice = prompt("Do you choose rock, paper or scissors")
var computerChoice = Math.random()
console.log (computerChoice);
if (computerChoice <= 0.33){
computerChoice = "rock";
} else if(computerChoice = 0.34 && computerChoice <= 0.66){
computerChoice="scissor";
}else{
computerChoice = "cut";
}
console.log(computerChoice);


#8

It work!!
thanks guys


#9

it helps me thanks...


#10

This is my code. It's working..

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";
}
var compare = function(choice1, choice2){
if(choice1 === choice2){
return "The result is tie!";
}
else if (choice1 === "rock") {
if(choice2 === "paper"){
return "Paper wins";
}
else{
if(choice2 === "scissors"){
return "rock wins"
}
}
}
else if(choice1 === "paper"){
if(choice2 === "rock"){
return "paper wins";
}
else{
if(choice2 === "scissors"){
return "scissors wins";
}
}
}
else {
if(choice2 ==="rock"){
return "rock wins";
}
else {
if(choice2 === "paper"){
return "scissors wins";
}
}
}
};
console.log("User choice: " + userChoice);
console.log("Computer Choice: "+ computerChoice);
console.log(compare(userChoice, computerChoice));


#11

Hi! I'm just curious on how you ended with:

else if(computerChoice = 0.34 && computerChoice <= 0.66)

What does the && and do? I don't think the previous lessons have tackled this.
Thanks


#12

&& means "and" so both of the parameters have to be met to result in "true"


#13

can you explain to me the reason why you got this answer ;

console.log(computerChoice);

for this question 2:
In the respective code blocks, change the value of computerChoice based on the rules stated above. Remember, you do NOT have to use var when changing the value of a variable that already exists.