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 trial

JavaScript

In 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
Steven Parker
229,708 Points

That 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.

Thank 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
Steven Parker
229,708 Points

That's the same snapshot link (with the "Malformed arrow function parameter list").

Steven Parker
Steven Parker
229,708 Points

It 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

Thank 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
Steven Parker
229,708 Points

Looks 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.

Thank 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.

https://w.trhou.se/o6g4pynbg3

Steven Parker
Steven Parker
229,708 Points

That's the same snapshot link that you posed yesterday and I responded to previously.

sorry about that, here it is: https://w.trhou.se/tllwr6eaci

I appreciate your time.

Line 16 says to add the const to the event listener so here is the snapshot where I added it:

https://w.trhou.se/ex82bvdk5l

Steven Parker
Steven Parker
229,708 Points

First, 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

https://w.trhou.se/62mm2lxp7h

Hi Steven, I hope you haven't left yet. Please check this out. I'm getting returns but undefined.

https://w.trhou.se/rsk3ih01g4

Hi 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
Steven Parker
229,708 Points

In 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. :wink:

https://w.trhou.se/0gxnmow1dl

This 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.

https://w.trhou.se/1vkux26ws2

I figured out how to use randomNumber instead. Let me know what you think. Thank you!

I just discovered the two random numbers aren't displaying on the page, only the console. : (

https://w.trhou.se/w5t56zj8ds

I 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?

https://w.trhou.se/ql7rp02xrh

My newest version.

Steven Parker
Steven Parker
229,708 Points

Pressing the button and seeing the results is the best confirmation. :+1:
Glad you got it going, and happy coding!

Thanks so much Steven!!!