Question 8- I cannot find my error


#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 ("scissors wins")
}else{
return ("paper wins");
}
}
};
console.log (userChoice, computerChoice);


#2

In the future please post the number of the project you are working on. I was completely wrong because I was looking at project 4. You are working on project 8. I will continue to look into your problem however. You are missing ( ) parentheses around "The result is a tie!". Also missing one more { after return scissors wins. You are missing a semicolon. Missing var compare. Please remove last console.log at the end of your code. It does not belong at the end.

}
     <---- place curly brace here
}     <---- also missing semicolon
else if (choice1 === "scissors") {
if (choice2 === "rock") {
return ("scissors wins")
}else{
return ("paper wins");
}
}
};
var compare = function (choice1, choice2) <-- Missing
{
if (choice1 === choice2)  <-- Missing
{
return("The result is a tie!"); <---- Missing
}
The rest of your problem can be solved by 
comparing this snipett with your code you will
 see rock is where scissors should be etc.
==================================================
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");
}
}
};

#3

Thanks for the input. But when i tried your method, it did not work. My code was:

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");
}
}
// as you can see, i put scissors, paper, and all the others here and it worked for me. Only my formatting was incorrect.//
else if (choice1 === "scissors") {
if (choice2 === "paper") {
return ("scissors wins")
}else{
return ("rock wins")
}
}
};
compare (userChoice, computerChoice) `


#4

I am glad to see that you got it working. I am starting to think that maybe one would be better off running the code in the lessons through the validators https://jigsaw.w3.org/css-validator/ (css) https://validator.w3.org/ (html) and then offering advice. If you find a trust-worthy js validator please let me know. My code passed in the manner in which I posted. I know how frustrating it is with these courses and that is why I respond. You never know if it was a bug or your own error causing it not to pass.:smiley: Also starting to realize that when I respond I will need to state in a help desk manner "Hello I am using Mozilla Fire Fox, your results may differ.":smiley: