Parameter not defined

Hey guys,i hope you're all good and having a good day. I'm doing a JavaScript course and i can't really figure this out. I'm trying to display under the buttons another 2 paragraphs,one with the result which it does display when you play the game, and another one that displays the hand of the player and the hand of the computer. The problem is with the "hands" paragraph, on the console it keeps saying "Uncaught ReferenceError: playerMove is not defined ". But "playerMove" is a parameter and i don't know what to do. I tried researching for similar problems but couldn't find an answer,declaring the parameter,reviewed the code and nothing. Here's the code pen https://codepen.io/JC-Dsc/pen/BaqWdqd?editors=1111 And thanks for the help
8 Replies
Jochem
Jochem2y ago
run the "format javascript" option from the context menu, you'll see that the console.log is outside of the function it's unbelievably important, especially when you're starting out, to have consistent and appropriate formatting. Either do it manually, or use something like prettier if your code isn't consistently formatted, you're making it 10x harder to read than is necessary, and code is already 10x harder to read than it is to write even with perfect formatting
JC-Dsc
JC-DscOP2y ago
I forgot about that,thanks for pointing that! But i was reffering to the function function "updateHandsElement",when i call the function it says that the "playerMove" is not defined. i'm sorry for the confusion btw
vince
vince2y ago
Could maybe be how you're calling the function in an onclick
JC-Dsc
JC-DscOP2y ago
How so? I’m sorry as I’m learning I really try to understand how things work
Jochem
Jochem2y ago
that variable is just not in scope there playerMove is only defined as a parameter of playGame, right? That means that that variable only exists inside of playGame, and nowhere else it doesn't matter where you call updateHandsElement from, the scope is determined when it's defined not when it's called
vince
vince2y ago
The way you wrote your functions could be better. The big picture is that you don't want to rely on global variables, make use of function arguments and their ability to read and modify variables Let me know if that doesn't fix it and/or you have questions
JC-Dsc
JC-DscOP2y ago
It’s solved yes! Thank you both for the help,I guess I’ll have to take a deeper look into functions, until I truly understand them.
Want results from more Discord servers?
Add your server