Spot the parsing error win an imaginary prize haha


#1

unexpected "{" in my code, but don't see it...

can be found here : https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/4?curriculum_id=506324b3a7dffd00020bf661#

SyntaxError: Unexpected token '{'. Parse error.

please correct me with any other bad writing practices, find the parse -pretend its wally :) 

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);

function compare (choice1, choice2 ) {
    if (choice1 === choice2) {
        return "The result is a tie!";
    }
    
    else if (choice1 === "rock") {
        
        if (choice2 === "scissors") {
         return "rock wins";
        }
        
        else (choice2 === "paper") {
            return "paper wins";
        }
        
    }
    
    else if (choice1 === "paper") {
    
        if (choice2 === "rock") {
        return "paper Wins";
        }
        
        else (choice2 === "scissors") {
        return "scissors wins";
    } 
    
     else if (choice1 === "scissors") {
    
        if (choice2 === "rock") {
        return "Rock Wins";
        }
        
        else (choice2 === "paper") {
        return "scissors wins";
    } 
}

compare(userChoice, computerChoice);

#2

if/else syntax:

if (condition) {
    block of code to be executed if the condition is true
} else { 
    block of code to be executed if the condition is false
}

if (condition1) {
    block of code to be executed if condition1 is true
} else if (condition2) {
    block of code to be executed if the condition1 is false and condition2 is true
} else {
    block of code to be executed if the condition1 is false and condition2 is false
}

Please, review your if/else statements.


#3

thanks...

i see i put them all in one... thanks


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.