PLEASE PLEASE HELP on this one - 7


#1

I am pulling my hair out. can you please help me find the errors:

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 "paper wins"}
}
else{return "scissors wins"}

};
else if(choice1 === "paper")
{if(choice2 === "rock")
{return "paper wins"}
else{return "scissors wins"
}
}


#2

1.At first remove

else{return "scissors wins"} }; //wrong

2 . close the function
add }

3.call the function
example:

var hello = function() {
console.log("i am saying hello");
};
hello();//Calling the function


#3

I made this same mistake. I'll just say this. If I throw rock and you throw scissors, how does paper win?


#4

//You just have some syntax errors it seems, here is mine
// The semi-colon after the return statements pop out at me real quick
// It seems you close your function early also by the closing }; being in the wrong spot between the
// the last two else if's. It should just be a regular } right there and it seems you need to
// add the }; to the very end after the last else if you made.

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

var computerChoice = Math.random();
console.log("Computer creates random # " + computerChoice);

if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
console.log("Computer changes # to object: " + 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);


#5

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

var computerChoice = Math.random();
console.log("Computer creates random # " + computerChoice);

if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";
} 
console.log("Computer changes # to object: " + 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);