Help with Rock, Paper Scissors Assignment


#1

Okay. This has been driving me nuts for a while ( 4 days ), so i created a function called computerPlay that will randomly return either ‘Rock’, ‘Paper’ or ‘Scissors’. I also created a function that plays one round that takes two parameters - the playerSelection and computerSelection. I also created a function that prompts the user to enter their selection ( not sure if thats what i was supposed to do. But if i console.log(playRound(playerSelection(), computerPlay())) It works fine, but i am feeling unsure if i am doing this correctly. This might sound dumb but in the picture below in the assignment i see const playerSelection = 'rock", whats up with that?

Also i see const computerSelection = computerPlay();

( i kinda understand this, so could i use my prompt like so?

let userChoice = playerSelection():
let computerSelection = computerPlay():

and pass these variables/arguements into the function of playRound? i.e playRound(userChoice, computerSelection) to run a single round?

Then i see console.log(playRound(playerSelection, computerSelection))

Why are they passing the argue of rock into playerSelection? i get the computerSelection part, it runs the function to get a random rock paper or scissors for the computer.

Also step 5, it asks to run a game for 5 rounds and keep score, im guessing we have to use loops for this, but we havent learned about those yet, they are actually the next lesson. If anyone could help that would be great and any tips would greatly be appreciated. This has me at my wits end. If i am unclear, please accept my apologies, this has kinda deflated my learning a bit, and i feel very stuck, but i hope i can get some help in solving this issue to move on.

Here is a link to my code in codepen.

https://codepen.io/hector4213/pen/jOEOdme


#2

They just assigned rock to the playerSelection variable for sake of testing.

No need to do this, because your playerSelection() function already prompts the user for argument and then returns the value user typed in. Also no need to assign computerPlay() to anything, because this function randomly chooses an argument and the returns it.

All you need to do is just playRound(playerSelection(), computerPlay()).

You don’t need any loop for that. Just set up some variables to count scores of players and when one of them hits 5 wins, do something.


#3

Thanks for your reply. I was hoping someone would! I’ll work on it tonight and see how it goes. I appreciate the guidance. Many thanks