Skip to content
Advertisement

How do I make images change with a rock, paper, scissors game?

I’m trying to build a Rock Paper Scissors game in JavaScript, but also have it where the computer outputs images to the HTML document. I’ve tried everything I know, and it won’t work. Here’s the HTML:

JavaScript

And here’s the JavaScript:

JavaScript

The “rock.png”, “paper.png”, and “scissors.png” are based on their respective items, and “blank.png” is just a transparent image. This program will always display “rock.png” for my choice and nothing for the computer’s. What am I doing wrong?

Advertisement

Answer

Your logic is not right, you are using = where it should be ==

For example look at my changes to this method, you have issues like this in all your methods.

JavaScript

For simplicity you could just do this:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement