Please help with Rope


#1


Step 9 of Rock paper scissors

Can anyone spot the error? Trying to add rope to the options.

SyntaxError: Unexpected token else


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

if (userChoice !== "rock" + "paper" + "scissors" + "rope") {
    var userChoice = prompt("Pick again!");
    console.log("My choice (again): " + userChoice);
}

var computerChoice = Math.random();
if (computerChoice <= 0.33) {
	computerChoice = "rock";
} else if (computerChoice <= 0.67) {
	computerChoice = "paper";
} else if (computerChoice <= 0.90) {
	computerChoice = "scissors";
} else {
    computerChoice = "rope";
} 
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 if (Choice2 === "paper") {
            return "paper wins";
        } else {
            return "rope wins";
    }
    
    else if (Choice1 === "paper") {
        if (Choice2 === "rock") {
            return "paper wins";
        } else if (Choice2 === "scissors") {
            return "scissors wins";
        } else {
            return "paper wins";
    }
    
    else if (Choice1 === "scissors") {
        if (Choice2 === "rock") {
            return "rock wins";
        } else if (Choice2 === "paper") {
            return "scissors wins";
        } else {
            return "scissors wins";
    }
    
    else (Choice1 === "rope") {
        if (Choice2 === "rock") {
            return "rope wins";
        } else if (Choice2 === "paper") {
            return "paper wins";
        } else {
            return "scissors wins";
    }
};

compare(userChoice, computerChoice);


#2

First off, keep the probability equal for all outcomes, 0.25.

var c = computerChoice; // for brevity

if (c < 0.25) {
    computerChoice = 'rock';
}
else if (c < 0.5) {
    computerChoice = 'paper';
}
else if (c < 0.75) {
    computerChoice = 'scissors';
}
else {
    computerChoice = 'rope';
}

Now we need to determine all the outcomes. We know there are total of sixteen possible outcomes, of which we can elliminate four (all ties).

var compare = function (choice1, choice2) {
    if (choice1 === choice2) {
        return "The result is a tie!";
    }
};

That leaves twelve outcomes remaining. What will 'rope` defeat? Here we have two choices in our game design. Only one win scenario for choice2; or, two win scenarios for choice 2. Let's work with one, for now.

rock smashes scissors
paper covers rock
scissors cut paper
rope hogties scissors

So let's set up our first choice1, 'rock'

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

Follow this pattern for the remaining three cases. Remember to insert these into the compare function body.


#3

Thank you!! that helped the structuring :slight_smile: