Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7436949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:19:16+00:00 2026-05-29T10:19:16+00:00

What I’m trying to do is simulate a simple paper, rock, scissors game within

  • 0

What I’m trying to do is simulate a simple paper, rock, scissors game within a page, where one player selects r/p/s with radio buttons, submits his choice, and player 2 does the same.

I have no doubt there are multiple problems to this code, but I see really weird stuff returned whenever I try and run the function that resolves the rock/paper/scissors. I always get a true on the:

else if (player1Choice("Rock") && player2Choice("Scissors")) {
        $("resultOutput").value = "Player 1s Rock beats Player 2s Scissors";
    }

I get this back as my result every time. I’ve stared at the function so long I’m probably just blind to an obvious resolution at this point.

// create our $() shortcut function for easily retrieving elements by id
var $ = function(id) {
    return document.getElementById(id);
}

//function executed on page load
window.onload = function() {

    //clear any previous values
    document.forms[0].reset();

    //store value from player1Weapon radio choice with the player1Choice function
    $("player1Submit").onclick = player1Choice;

    //store value from player1Weapon radio choice with the player2Choice function
    $("player2Submit").onclick = player2Choice;

    //assign the fight button to run the fightCrunch function to determine the winner
    $("fight").onclick = fightCrunch;
}

var player1Choice = function(x){
    var a = "Paper";
    var b = "Rock";
    var c = "Scissors";
   //the html has several radio buttons with id's of "player1Paper", etc. the $ function is to get the id name, and then I'm doing if, else ifs to see which on is checked.
    if ($("player1Paper").checked) {
        return a;
}
else if ($("player1Rock").checked) {
    return b;
}
else if ($("player1Scissors").checked) {
    return c;
}
else {
    alert("Player 1, you need to pick a crude instrument of violence first");
}
};

var player2Choice = function(y){
    var d = "Paper";
    var e = "Rock";
    var f = "Scissors";
    //var d = $("player2Paper").value;
    //var e = $("player2Rock").value;
    //var f = $("player2Scissors").value;
    if ($("player2Paper").checked) {
        return d;
}
else if ($("player2Rock").checked) {
    return e;
}
else if ($("player2Scissors").checked) {
    return f;
}
else {
    alert("Player 2, you need to pick a crude instrument of violence first");
}
};

var fightCrunch = function(){
        //The next few lines are commented out because the if gets hung up on this part, this always comes back as true no matter what I do with the previous functions.
    //if (player1Choice || player2Choice == undefined) {
        //alert("Both players need to select and submit a weapon of choice before a winner is determined");
    //}
    if (player1Choice && player2Choice == "Rock") {
        $("resultOutput").value = "Both players chose Rock, which results in a stalemate";
    }
    else if (player1Choice && player2Choice == "Paper") {
        $("resultOutput").value = "Both players chose Paper, which results in a stalemate";
    }
    else if (player1Choice && player2Choice == "Scissors") {
        $("resultOutput").value = "Both players chose Scissors, which results in a stalemate";
    }
    else if (player1Choice("Rock") && player2Choice("Scissors")) {
        $("resultOutput").value = "Player 1s Rock beats Player 2s Scissors";
    }
    else if (player1Choice("Rock") && player2Choice("Paper")) {
        $("resultOutput").value = "Player 2s Paper beats Player 1s Rock";
    }
    else if (player1Choice("Paper") && player2Choice("Rock")) {
        $("resultOutput").value = "Player 1s Paper beats Player 2s Rock";
    }
    else if (player1Choice("Paper") && player2Choice("Scissors")) {
        $("resultOutput").value = "Player 2s Scissors beats Player 1s Paper";
    }
    else if (player2Choice("Paper").value && player1Choice("Scissors")) {
        $("resultOutput").value = "Player 1s Scissors beats Player 2s Paper";
    }
    else if (player2Choice("Rock").value && player1Choice("Scissors")) {
        $("resultOutput").value = "Player 2s Rock beats Player 1s Scissors";
    }
    else {
        alert("something is wrong here");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:19:17+00:00Added an answer on May 29, 2026 at 10:19 am

    Your code has quite a few problems. But the problem you are asking about stems from the way you are doing comparison.

    You cannot do this:

    if (player1Choice && player2Choice == "Rock")
    

    What that meant is essentially:

    if ((player1Choice == true) && (player2Choice == "Rock"))
    

    Instead, you want to write it this way (but it will still not work because of many other errors):

    if (player1Choice == player2Choice) {
        $("resultOutput").value = "Both players chose " + player1Choice + ", which results in a stalemate";
    }
    

    Not only do you have less comparison operations, you also save many lines of code!

    Do note that you have additional typos in the last 2 comparisons where you added “.value” erroneously.

    On top of that, you might want to note that the functions player1Choice and player2Choice are not variables. You have specified for them to be event handlers for click events. The values they return go no where and will not be received by the fightcrunch function.

    I do not really want to spoil your fun with making this program, but if you do give up, you can see corrected and functional code here (it is tabbed to the right in case you do not want to see it):

                                                                                    <form>
                                                                                        Player 1
                                                                                        <select id="player1">
                                                                                            <option value="0" selected>Paper</option>
                                                                                            <option value="1">Rock</option>
                                                                                            <option value="2">Scissors</option>
                                                                                        </select>
    
                                                                                        Player 2
                                                                                        <select id="player2">
                                                                                            <option value="0" selected>Paper</option>
                                                                                            <option value="1">Rock</option>
                                                                                            <option value="2">Scissors</option>
                                                                                        </select>
    
                                                                                        <input type="submit" id="fight" value="Fight">
                                                                                    </form>
    
                                                                                    <div id="resultOutput"></div>
    
    
                                                                                    <script> 
                                                                                        // create our $() shortcut function for easily retrieving elements by id
                                                                                        var $ = function(id) {
                                                                                            return document.getElementById(id);
                                                                                        }
    
                                                                                        //function executed on page load
                                                                                        window.onload = function() {
    
                                                                                            //clear any previous values
                                                                                            document.forms[0].reset();
    
                                                                                            $("fight").onclick = fightCrunch;
                                                                                        }
    
                                                                                        var fightCrunch = function(){
    
                                                                                            var choices = ["Paper", "Rock", "Scissors"];
                                                                                            var player1 = $("player1").value;
                                                                                            var player2 = $("player2").value;
                                                                                            var result = "";
                                                                                            var diff = player1 - player2;
    
                                                                                            if (!diff)
                                                                                                result = "Both players chose " + choices[player1] + ", which results in a stalemate";
                                                                                            else if (diff == -1 || diff == 2)
                                                                                                result = "Player 1's " + choices[player1] + " beats Player 2's " + choices[player2];
                                                                                            else
                                                                                                result = "Player 2's " + choices[player2] + " beats Player 1's " + choices[player1];
    
                                                                                            $("resultOutput").innerHTML = result;
                                                                                            return false;
                                                                                        }
    
                                                                                    </script>
    

    Good luck!

    Edit: Using return and global variables

    var player1Choice, player2Choice;
    
    window.onload = function () {
    
        //clear any previous values
        document.forms[0].reset();
    
        //store value from player1Weapon radio choice with the getPlayer1Choice function
        $("player1Submit").onclick = function () {
            player1Choice = getPlayer1Choice();
        };
    
        //store value from player1Weapon radio choice with the getPlayer2Choice function
        $("player2Submit").onclick = function () {
            player2Choice = getPlayer2Choice();
        };
    
        //assign the fight button to run the fightCrunch function to determine the winner
        $("fight").onclick = fightCrunch;
    }
    
    function getPlayer1Choice () {
        //...
        // return ...;
    }
    
    function getPlayer2Choice () {
        //...
        // return ...;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.