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

Random Array Project

How do I get code to run by clicking the play button so that two random numbers for two players competing to get the highest number reveals in the console?

9 Answers

I thought I corrected all of the lines you mentioned again. For instance, Line 25 was corrected to function diceRoll{(array)

Steven Parker
Steven Parker
231,153 Points

The very first hint was "line 25: there's a stray brace ... between the function name and the parentheses"
But that still needs fixing. :see_no_evil:

Get some rest and come back to it fresh. :wink:

Steven Parker
Steven Parker
231,153 Points

Creating an event listener on the button for the "click" event is what allows the button to work. But it uses other parts of the code, so that won't work until you have coded all the individual steps.

If you've completely coded everything and it's still not working, post a fresh snapshot.

Steven Parker
Steven Parker
231,153 Points

There's a few code issues:

  • line 25: there's a stray brace (and space) between the function name and the parentheses
  • lines 48/49: these should be new varaibles ("scoreOneElement" and "scoreTwoElement" are already used)
  • also 48/49: new variables need the "let" or "var" keyword to declare them
  • line 52: not needed, duplicate of 55
  • line 55: should be logging the new variables with values and not the elements
  • step 6 says to use "innerHTML" instead of "textContent"
  • lines 59/60: should assign from the new variables instead of calling "diceRoll" again
  • line 68: there's a stray undefined identifier "cccccc" at the end of the line

Can you take a look please. I'm stuck. Please help

https://w.trhou.se/xs5ysa6gw8

Steven Parker
Steven Parker
231,153 Points

Those new variables on lines 48/49 need unique names, "scoreOneElement" and "scoreTwoElement" are already taken. Then the other lines where they are used will need to be updated, and 59 and 60 will use them instead of "twelveSidedDie".

Steven Parker
Steven Parker
231,153 Points

Maybe you got a bit hasty, read the comment for step 6 again carefully:

// 6) Set the innerHTML of the `scoreOneElement` and `scoreTwoElement` variables above equal to the dice roll variables you just created 
Steven Parker
Steven Parker
231,153 Points

The button will work when the errors have been fixed, assuming no new problems are created.

The remaining issues are on lines 25, 48, 49, 59, 60.

I don't know what I am doing wrong. Very frustrated because it is due soon. I do not know what it should be corrrected to. https://w.trhou.se/mke8rlpbij

Steven Parker
Steven Parker
231,153 Points

Frustration may be becoming an obstacle in itself. It could be time for a break. Come back fresh and the instructions in the comments combined with the hints given here may make more sense.

I cannot get play button to work

Steven Parker
Steven Parker
231,153 Points

Once you've checked all the hints and the comments in the instructions again, and made your best effort to fix those 5 lines with issues, post a fresh snapshot link.

I really hope this is correct... Line 6 towards the bottom, not sure if correct but I believe so. Play button works! Can someone take a look please....https://w.trhou.se/vn763371we

Steven Parker
Steven Parker
231,153 Points

That snapshot doesn't exist, did you delete the workspace it was made from?
Try making a fresh one ... or did you get things working?

Sorry for the delay in response. Yes! I was able to get the code running. Thanks for all your help.

Steven Parker
Steven Parker
231,153 Points

Brittney Scott — Glad to help. You can mark the question solved by choosing a "best answer".
And happy coding!