Lesson 6 & 7 Where else?


#1

So I am having difficulties putting indents in my code, i think in terms of layouts and what block is with what block and that is the issue that I am having with my code. Can you spot the flaw of my thinking and the best way to layout the else block?

...
/*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 win"
}
}
}
}
...


#2

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

else{

Combine these

if (choice1 === "rock"){

So it looks like

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