8. what if choice1 is scissors, need help with my syntax


#1

This is my code, I'm stuck and I have still problem with my syntax... Could somebody help me?

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

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";
   }
}   
if(choice1 === choice2){
    return "The result is a tie";
}

else if(choice1 === "paper"){

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

}

if(choice1 === choice2){
    return "The result is a tie";
}

else if(choice1 === "scissors"){

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

}
};


#2

your tie message lacks a ! at the end also why do you have it 3 times? Ones is sufficient. It's not a syntax error but is it planned that scissors can not win?


#3

Ok. I repaired my code, but I still have message: sytax error: unexpected token { . I don't have more idea's :frowning: Maybe someone show me correct form for this lesson? Beacuse time is money.

My actually code:

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

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

};
console.log(computerChoice&&userChoice);


#4

OK! I did it ... In erlier lessons evrything it was ok. I doing new lessons easly, but in lesson 8 I was forced to change my code ... My question is: What I am doing these lessons up to and I am folding them into the whole in order in the last lesson to learn that I must change something what I did earlier and was "supposedly" okay?

I change this part of code and it's working:

if (computerChoice < 0.33) {
computerChoice = "rock";
}
else if (computerChoice<= 0.66) {
computerChoice = "paper";
}
else {
var computerChoice = "scissors";
}


#5

Well in the lessons from 5 to 8 this code was a comment and comments are just for you and other human readers the computer just ignores them. So unless a test function might use code.substring to get them, they are just treated as not existing. But the condition after else should have also raised an error in the exercise where you initially used it.