8/9 what am i doing wrong?


#1

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";
}
}
else if (choice1==="scissors"){
if (choice2==="rock") {
return "rock wins"; }
else {
return "scissors wins";
}
}
}
compare (userChoice, computreChoice);


#2

you have an extra bracket at the bottom after scissors wins.

and the console.log for the computerChoice should look like this: console.log("Computer:" + " " + computerChoice);


#3

thanks but is not working


#5

in your second to last else if statement change it so that the quotes are only around "paper", and that should be it (well at least from how i see it).


#6

At the bottom -computreChoice


#7

the problem is still the same


#8

you didn't place a semi colon before you called then function. the last part should be like this
else if(choice1 === "scissors")
{if (choice2 ==="rock"){return "rock wins";}
else {return "scissors wins"}}};
compare(userChoice,computerChoice);


#9

i place the semi colon end is the same problem


#10

another error, where choice1 is equal to paper you coded else if ("choice1===paper") instead of else if (choice1==="paper")


#11

try this instead, I ran your code through a debug program

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";
}
}
else if (choice1==="scissors"){
if (choice2==="rock") {
return "rock wins"; }
else {
return "scissors wins";
}
}
};
compare (userChoice, computreChoice);


#12

Yes you are right ..i code: else if (choice1==="paper") and now it works ..Thank you very mucs


#13

//This is the whole code for rocks papers scissors:
//Copy paste this code if needed cheers! Happy Coding!
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";
}
}
else if (choice1==="scissors")
{
if(choice2==="paper"){
return "scissors wins";
}
else{
return "rock wins";
}
}

};
compare(userChoice,computerChoice);