Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBaheejah Fareed
3,450 PointsIn the project, I need help understanding a console error message:
https://w.trhou.se/0pegwzax45 Uncaught SyntaxError: Malformed arrow function parameter list https://w.trhou.se/0pegwzax45
14 Answers
Steven Parker
231,269 PointsThat error refers to line 47 where a callback function is defined with several syntax issues (only one is reported):
playBtn.addEventListener('click', getUserName) => { // line 47 now
playBtn.addEventListener('click', () => { // a typical arrow function definition
But there are numerous other unreported issues elsewhere in the code. It looks a bit like two unrelated projects have been mixed together here, evidenced in part by the comments. For instance, there are two step "3" lines, and one of them comes between "2" and "2a".
You may need to back-track or start over to be sure that only code that belongs to this particular project gets included.
Baheejah Fareed
3,450 PointsSteven Parker
231,269 PointsIt looks like there are still things to work on, these stood out at first glance:
- item 2 is to create the function "diceRoll" to pick a random value, but it is empty
- items 2a and 2b should be inside the function
- 2b says to return the number, but the code logs it instead
- item 3: the event listener callback function should have a code body, but it just returns "1" instead.
- 4a says to set the variables by calling "diceRoll", but they are set to 0 instead
- after 4a a function "getDiceRoll" is defined but is not part of the instructions
- after that, there are some loops that are also not part of the instructions
- item 5 says to log out two variables, but the code calls log without any arguments
- item 6 says to set the elements using the variables, but the code sets them to the function "diceRoll" instead
Baheejah Fareed
3,450 PointsThank you so much Steven! Will you please look at my new screenshot to give me feedback after I went through the items that you mentioned? https://w.trhou.se/o6g4pynbg3
Steven Parker
231,269 PointsLooks like you missed one issue and created a few new ones:
- line 47, doesn't make sense, purpose not clear
- 48, alert is not part of the instructions
- 49, why log an event object?
- 50, callback should not end here, it should enclose all remaining code
- 61, the function "getDiceRoll" is defined but is not part of the instructions
- 62/63, these calls are incomplete and both need parentheses with the argument
- 68, not part of the instructions
- 69, values should be logged separately instead of added together
- 73/74, invalid assignment operator
And remember to delete the duplicate question.
Baheejah Fareed
3,450 PointsThank you Steven!
Please check out my new snapshot.
I am not getting console errors but now the game isn't working (not returning the two players random dice rolls).
At one point with other errors it returned numbers.
Your expertise and direction is very much appreciated and I'm better understanding how everything works together with your guidance.
Steven Parker
231,269 PointsThat's the same snapshot link that you posed yesterday and I responded to previously.
Baheejah Fareed
3,450 Pointssorry about that, here it is: https://w.trhou.se/tllwr6eaci
I appreciate your time.
Baheejah Fareed
3,450 PointsLine 16 says to add the const to the event listener so here is the snapshot where I added it:
Baheejah Fareed
3,450 PointsSteven Parker
231,269 PointsFirst, be careful to follow this very important tip: Don't change anything that is not broken.
Then, the issues are:
- the "diceRoll" function used to work, but now it does not return the
randomNumber
- line 32, this isolated call doesn't do anything useful and is not part of the instructions
- lines 47/48 were added since last time and are overriding two important variables set earlier
- line 58, as mentioned last time, the callback should not end here but should include all remaining code
- lines 61/62, values should be logged separately and not added to anything
Baheejah Fareed
3,450 PointsHi Steven, I hope you haven't left yet. Please check this out. I'm getting returns but undefined.
Baheejah Fareed
3,450 PointsHi Steven, I'm getting random numbers for player one but player two is undefined. Seeking your guidance and expertise to spot any discrepancies in my code.
Thank you!
Steven Parker
231,269 PointsIn hopes of avoiding important fixes getting skipped or creating new issues by making changes to working parts of the code, please make sure you understand how the suggested changes relate to the project instructions before proceeding.
So there are two major issues at the moment. The first one is that the "diceRoll" function, which was working several versions ago, has been changed and now it's not doing what the comment instructions say it should. Check the instructions in the comments marked 2, 2a, and 2b again. It needs to randomly select and return a value. It should not change any variables that don't belong to it (that means any that are created outside of the function).
The other issue has been mentioned in the last 2 rounds of hints and is that on line 63 (in the latest snapshot) the callback function ends. But it should not end here, it should contain all the rest of the code. The rest of the code is needed to update the card images on the page when the button is pushed, so the ending symbols should be moved to the very end of the file.
I'm betting you can get it going this time.
Baheejah Fareed
3,450 PointsThis code is working. When I tried to put the ending symbols at the very end it wouldn't work. It only worked after the console.log. I think I fixed 2, 2a, and 2b as you mentioned and the other issues. Please let me know what you think. I'm reading over it again.
Baheejah Fareed
3,450 PointsI figured out how to use randomNumber instead. Let me know what you think. Thank you!
Baheejah Fareed
3,450 PointsI just discovered the two random numbers aren't displaying on the page, only the console. : (
Baheejah Fareed
3,450 PointsI was finally able to get it to work by adding the ending symbols at the very end. ; ) I'm checking over it. Will you help me check over it please?
Baheejah Fareed
3,450 PointsMy newest version.
Steven Parker
231,269 PointsPressing the button and seeing the results is the best confirmation.
Glad you got it going, and happy coding!
Baheejah Fareed
3,450 PointsThanks so much Steven!!!
Baheejah Fareed
3,450 PointsBaheejah Fareed
3,450 PointsThank you very much Steven! I followed your instructions. Will you please check out my code now (link below), and tell me your thoughts? I am not getting any errors in the console, but as a rookie I know I am not expert at this yet, and understanding everything fully will come soon. I love coding and hope I'm good enough to start towards a Tech degree.
https://w.trhou.se/0pegwzax45
Steven Parker
231,269 PointsSteven Parker
231,269 PointsThat's the same snapshot link (with the "Malformed arrow function parameter list").