Rock, Paper, Scissors won't return any results


I get no results. The game itself works via popup messages, I don't mind that, but the last thing it shows me is what the computer picks, doesnt tell who won

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";
        window.alert("Computer picks " + 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 wins";
            } else if (choice1 === "scissors") {

                if (choice2 === "rock") {
                    return "rock wins";
                } else if (choice2 === "paper") {
                    return "rock wins";


        alert(compare(userChoice, computerChoice));


Instead of that you need this:

compare(userChoice, computerChoice)

The difference? I am not quite sure. I do not believe the alert is necessary but other than that it is still a bit of a mystery to me at least.


if something is returned, it means the function hands you something in return, so what you could do is logged this returned result to the console:

console.log(compare(userChoice, computerChoice))


any difference between mine

and yours?


i use console.log() to logged the returned result by the function?


Yeah, I know that, I was just wondering if their was any difference in what would be put up on the screen for the code. I figured not. Usually when someone answers a forum post after you post your answer something is different or you missed something in your answers so yeah xD



Might not always be logged to the console, it depends on the console unit you use, so i am rather safe then sorry by just using console.log


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