Does not show who wins the game


#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 ( usercChoice, computerChoice) {
if (usercChoice === computerChoice) {
return "The result is a tie";
}
else if( usercChoice ==="rock") {

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

};


#2

You need to call the function.


#3

how ? as in userChoice()


#4

or useChoice= choice1 and computerChoice=choice2 ?


#5

compare(userChoice, computerChoice)

then the value of your first argument userChoice get assigned to your first parameter usercChoice and the second argument computerChoice get assigned to the second parameter computerChoice. And this also happens if they do not share the same name :slightly_smiling:


#6

Thankyou , one more thing im trying something as a way to recognise different words.

if( if (!"rock",!"paper",!"scissors") {
prompt ("You're playing the wrong game buddy?")
I need some guidance from here ,AS is that right and what wrong about it ?


#7

Well not equal is done by != and !== and for chaining multiple condition you might search for the boolean operators && (AND) and || (OR). e.g.

if( A && !B)

if A is true and B is not true.