7 what if choice1 is paper


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

i get a syntax error help!!!


#2

You've forgotten semicolons on the return statements.


#3

could you show me how to do that?


#4

return "Hi";

#5

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

still not working...


#6

Hi this part its missing a }

else if (choice1 === "rock"){
if (choice2 === "scissors"){
return "rock wins";
}
else {
return "paper wins";
}
}< == here for closing the else if statement

#7

What is your error, these usually explain the issue.


#8

SyntaxError: Unexpected token else


#9

it is still not working


#10

I changed the code too:

/*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"
}
}

But it still isn't working...


#11

Here
@lchrispijn try that

else if (choice1 === "rock"){
if (choice2 === "scissors"){
return "rock wins"
}
else {
return "paper wins"
}
}<== Add one here 
else if (choice1 === "paper") {
if (choice2 === "rock") {
return "paper wins"
} 
else {
return "scissors wins"
}
}
}<== here for the closing the compare function

#12

i got this...
SyntaxError: Unexpected token else


#13

guys @wizmarco @cadecodes
I got it!!!
here is the code!
/*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";
}
}
}

thx for helping i appreciate it!