Always returns "rock wins"


I don't have error messages, but everytime after I check my code, it will return the right answer and right after that it will always return "rock wins".
I checked when it returns the extra answer, and it's the last alert says "rock wins".

Replace this line with your code. 
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();

if(computerChoice < 0.33) {
    computerChoice = "rock";
}else if (computerChoice <= 0.67){
    computerChoice = "paper";
    computerChoice = "scissors";
}confirm("Computer: " + computerChoice);

var compare = function (choice1, choice2) {
    if(choice1 === choice2) {
      alert("The result is a tie!");
    }else if (choice1 === "rock") {
        if (choice2 === "scissors") {
            alert("rock wins");
            alert("paper wins");
    else if (choice1 === "paper") {
        if (choice2 === "rock") {
            alert("paper wins");
                alert("scissors wins");
    else if (choice1 === "scissors") {
        if (choice2 === "paper") {
            alert("scissors wins");
                alert("rock wins");
compare(userChoice, computerChoice)


If you use the Submit button
the code is run
the code you defined is checked by a code-checker.....
it does it's check's and will lead to your last-output.


What should be said....
The requirement was to use the return statement instead of the alert() statement....
If you call the compare function, in which you use the return statement
the returned Result has No-Display

Please read
and concentrate on:

  • the execution of the compare function (keeping in mind that the return statement is used )


Thanks for the reply :slight_smile:

I really want to use the alert() statement, will I learn how to use it with functions later on the course?


Do a google search
== discussions / opinions ==
alert() vs return
and read some of the articles......


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