Review DOM Manipulation by Building a Rock, Paper, Scissors Game - Step 3

Tell us what’s happening:

it says my getRoundResults should return a string.
I thought the return for each of the loops did that. I’m also getting something in the console that says player and computer are not defined, but maybe I’m understanding parameters incorrectly?
tbh I did cheat a little but and went to the next section to see what I was doing wrong, but I’m still confused.

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

function getRoundResults(userOption) {
  const computerResult = getRandomComputerResult();
 if (hasPlayerWonTheRound(player, computer)) {
    playerScore++;
    return `Player wins! ${userOption} beats ${computerResult}`;
  } else if (computerResult === userOption) {
    return `It's a tie! Both chose ${userOption}`;
  } else {
    computerScore++;
    return `Computer wins! ${computerResult} beats ${userOption}`;
  }
}


// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 OPR/109.0.0.0 (Edition std-2)

Challenge Information:

Review DOM Manipulation by Building a Rock, Paper, Scissors Game - Step 3

Welcome to the forum @phrygianskittles

You have two errors.

Uncaught ReferenceError: player is not defined

Once you update your code, the console will give the second error.

You need to use the variables used elsewhere in your code.

Happy coding

I said as much in my post, so I understand that much.

function hasPlayerWonTheRound(player, computer) {
return (
(player === “Rock” && computer === “Scissors”) ||
(player === “Scissors” && computer === “Paper”) ||
(player === “Paper” && computer === “Rock”)
);
}

in step 2, the above code was used. am I supposed to declare const variables for player and computer in step 3’s writable section?

no, you need to pass the correct variables as arguments when you call hasPlayerWonTheRound inside getRoundResults, in getRoundResults there aren’t variables named player and computer , the variables have other names

so the variables I passed as arguments were (player, computer) which I had established in step 2 successfully with:
function hasPlayerWonTheRound(player, computer) {
return (
(player === “Rock” && computer === “Scissors”) ||
(player === “Scissors” && computer === “Paper”) ||
(player === “Paper” && computer === “Rock”)
);
}

The only way for me to progress from 3 to 4 was in fact to declare those arguments as variables.
function getRoundResults(userOption) {
const computerResult = getRandomComputerResult();
let player;
let computer;

if (hasPlayerWonTheRound(player, computer)) {
playerScore++;
return Player wins! ${userOption} beats ${computerResult};
} else if (computerResult === userOption) {
return It's a tie! Both chose ${userOption};
} else {
computerScore++;
return Computer wins! ${computerResult} beats ${userOption};
}
}

So if declaring them in the function for step 3 was not the correct answer, then I’m even more confused.
When I do not have those two variables, I would get an error saying the player was not defined. I have reset the lesson several times. I don’t know specifically where I am wrong.

and what values do they have? they are undefined. you need to pass the actual player choice and computer choice here

To be honest, I don’t know! That’s why I’m asking for help!
edit: before I added them, the console was giving me an error that said player was undefined. I figured it would do the same for the computer if I declared and uninitialized variable for player, so I did it for both.

It wouldn’t let me continue to step 4 without them, so if you’re telling me they’re not supposed to be there, then that’s where my understanding is breaking down.

What I’m trying to understand:
-Are there supposed to be variables? If not, then why did it work?
-If I remove the variables, then where is my error?

I’m still in the learning stages of Javascript and DOM Manipluation but if my understanding of functions is correct (very possible it may not be), in the if statement I would have used

if(hasPlayerWonTheRound(userOption, computerResult)

as those two variables are where you have stored the data the function is looking for. The player and computer variables would then be used within the function to return true or false.

I haven’t had a chance to test the solution as I’m in work.

Hopefully this works :slight_smile:

but it’s code you have written, you should know where the value of the player choice and the value of the computer choice are

Thanks for replying, that was one of the first things I tried, but it wasn’t correct. If I’m understanding correctly, those parameters have to be the same as the previous step because the if loop is checking to see what scenarios qualify as a win for the player.
If “if (hasPlayerWonTheRound(player, computer)) {}” used (userOption, computer Result) instead, then I don’t think it return anything since those aren’t the parameters used in the function that was given in the prompt for step 2.

It’s checking if the player chose rock(or scissors or paper) AND computer generated scissors (or paper or rock)
Or if it’s none of those three specific combinations, it’s checking to see if the answers are the same then saying it’s a tie
Or the computer wins since that’s the only unaccounted for combinations possible.

the parameters are in the function definition, and those are one thing

the arguments never have to have the same name as the parameters, the arguments give value to the parameters.

Please review how functions work

Each of your unhelpful comments has gotten progressively more condescending. If you’re not interested in helping or addressing my conviction, then please save us both the frustration and stop commenting.

I am working with the convitction that you know how functions work, but if you don’t, things are harder.

A function is defined with the function keyword, and it can have parameters. The parameters are variables that are given a value when a function is called.

So for a function

function sum(a, b) {return a+b;}

the parameters a and b are given a value when the function is called. For example, calling it like sum(8, 13), the parameter a will have a value of 8 and the parameter b will have a value of 13.

If you pass a value held in a variable, the variable name can be whatever.

const pineapple = 2;
const unicycle = 5;
sum(pineapple, unicycle) // returns 7

returning to this step, you need to call the function hasPlayerWonTheRound passing to it whatever is the value of the user choice and whatever is the value of the computer choice.

The function
hasPlayerWonTheRound(player, computer)
has two parameters to be added for the function to work.

Within your getRoundResults(userOption) function:
you have attempted to call the hasPlayerWonTheRound() function with the parameters “player, computer”.
Those two parameters are not arguments - but merely placeholders.

Instead of using (player, computer) -
Do you have variables and/or arguments within the 'GetRoundResults()` function that can be used as arguments for player and computer?

*** you do not need to declare empty variables… you already have everything you need from the script that was provided ***

If you are still lost - check out the “defining functions” on MDN web docs and see if that clicks.