Stuck with rock paper scissors


Here is my code, basically nothing works. computerPlay only selects the first element of the array “choices”, playRound comes out as undefined. Really have no idea what is happening.


It’s really hard for others to debug code with just a screenshot. You need to post a link to your code online, like in codepen or I’m not exactly sure why your choice array is always returning paper - I took the time to type in your screenshot into VS Code and then looked at in the browser and it seemed to work fine for me. However, this is where having your code online is essential for others to help debug - it could be simple typo or something like that… In addition, I would look at using console.log(variable name) inside the playRound function to make sure it is working like you expect it.

In addition, your playRound function will need to take into consideration what happens if there is a tie. For example, if both the playerSelection and computerSelection is both “rock”.

Finally, if you haven’t already - join the Discord channel. It’s a very active community & a great place to ask questions like this. Most of the time, I think you can get a quicker response.


I’m a bit of a noob myself, but it looks like you declared function playRound, but didn’t call it. Try calling it after you declare playerSelection and computerSelection, like this playRound(playerSelection, computerSelection);
Also, eventually, you’ll need to change your code to prompt the player for their selection. Good luck!