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
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.
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
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.
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.
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.
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.
instead of using: if (hasPlayerWonTheRound(player, computer)) { ...
you should write: if (hasPlayerWonTheRound(userOption, computerResult)) {...
because player and computer are not given variables in this function, but userOption and computerResult are given.
your problem will be solved right away.
function getRoundResults(userOption) {
const computerResult = getRandomComputerResult(); // this is a function which would iterate over rock paper sissor array and give the compute a random value.
if (hasPlayerWonTheRound(player, computer)) {
// the player won the round would check if player has won or not
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};
}
}