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 Index (Project): Code Review/Advice

Hello,

I a trying to figure out what is wrong with my code. I no longer have access to Treehouse videos. Running Chrome Cosole, I get an syntax error on line 36. The error reads:

Uncaught SyntaxError: missing ) after argument list on line 36

Where do I place my ) or }? How can I improve my code to complete this challenge?

https://w.trhou.se/ohlp0oh2mq

Steven Parker
Steven Parker
231,153 Points

It would be much easier to replicate the issue if you make a snapshot of your workspace and post the link to it here.

6 Answers

Steven Parker
Steven Parker
231,153 Points

My chrome directed me to line 17 instead, but that's just one of several issues:

  • comments enclosing (hiding) essential code on lines 9, 43, and 47
  • unmatched parentheses on line 17 (final closing one missing)
  • "celi" instead of "ceil" on line 17
  • spurious "var" on line 23
  • bad syntax on line 27 (should probably be a comment)
  • redundant copy of task 4 on lines 34-36
Steven Parker
Steven Parker
231,153 Points

UPDATE: Some of the issues I pointed out before still need to be fixed. Also, some of those "hidden" code lines in comments had both comments and code, they need to be split into separate lines to allow the code to be seen but to keep the comment as a comment (otherwise it causes a syntax error).

Once you get all the issues fixed, you'll know it works because clicking the button will cause numbers to appear on the cards.

Debugging hing: opening the console in the browser's dev tools can be helpful in finding issues.

I don't get what you mean. Can you annotate my code?

Here is my console: https://imgur.com/a/PQQOxWy

Steven Parker
Steven Parker
231,153 Points

Some of the original issues I mentioned were not fixed yet (like unbalanced parentheses on the line with "ceil").

And what I mean about the comments is this:

// this comment hides some code   var sample = doSometing(42);

But this comment is creating a syntax error   var sample = doSometing(42);

// the correct solution is to keep the comment as a comment and put the code on a separate line
var sample = doSometing(42);
Steven Parker
Steven Parker
231,153 Points

Another update, for the "Random Array Index_4.24.2020" version:

  • line 19 (used to be 17) is still missing a closing parenthesis
  • line 29 (was 27 before) should be a comment, it's not code and is causing a syntax error
  • line 44 is also not code and should be a comment

Fix those and it should work.

I updated my post!

I fixed it at https://w.trhou.se/ohlp0oh2mq.

How do I know that the dice roller works? I load it up but nothing happens when I hit play?

This is what my output looks like:

https://imgur.com/a/G4pm4WG

Thanks Steve, I deleted all the comments. When I output, I still get a play button that doesn't link and I don't see any dice. I really wish I could "see" what the finished webpage should look like because no numbers appear on the card. Can you take a look at my new code?

https://w.trhou.se/wutt5jqep3

Steven Parker
Steven Parker
231,153 Points

It seems the other way around in this snapshot. The comments are there but the code seems to be gone.

I moved everything that starts with a color down to its own line. I didn't delete any of the // or the /* because I deleted that all before (leaving all the colored stuff only) and you said I deleted the code and not the comments?

My output does not change at all so I can't see the effects of any changes made. https://w.trhou.se/g3rqiv8tp9

Could you provide an example like:

line 38 currently reads printconsole.log(scorePlayer1); printconsole.log (scorePlayer2);

when it should have just have console.log(scorePlayer1); because what you have originally does not tell the program to print.

therefore: writing console.log what you need to print the scores. If you want to display player 1's score after you print you would write:

DisplayScore1 (scorePlayer1);

I am working on getting the skills to speak machine language. Maybe it's a terrible example, but seeing code and the English translation side by side really helps because then I can compare what I did wrong against the correct version. I appreciate your help, very, very much and I hope I don't come across as rude as that is not my intention at all.

I wish treehouse would let you do the code checks like they did in the course. Maybe its too much of a crutch, but the code checks going task by task or line by line were so helpful.

Thank you!!