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 trialVictor Chiappetta
524 PointsBracket matching: I am getting lots of errors. Does anyone know how the wrapping works in the JS files?
I am asking for the structure within the JS files. As I follow along with the videos I am being asked to add code and as I do that the files are becoming littered with syntax errors. The layout of the JS file is as such: Object (ex. player) Constructor Variable w/ loops Additional variables with loops When I start, the player holds only the constructor with Variable w/ loops below. I would think that adding additional variables w/ loops within the existing variables with loops would be the solution. Not the case. If the additional variables with loops are declared outside the original variables with loops, I get an error. If I try and wrap everything in the Object, I get errors. Nots sure what the issue is here. The videos don't show a birds eye view of the solution. It seems there are only 3 combinations, but all fail. I was hoping to have this ready for a tutor session later today so that I could step through and try and really understand this code, but without correct syntax, that won't be able to happen.
class Player { constructor(name, id, color, active = false){ this.name = name; this.id = id; this.color = color; this.active = active; this.tokens = this.createTokens(21); /* return value from the method call */ } }
/**
- Creates token objects for player
- @param [integer] num - Number of token objects to be created / createTokens(num); { const tokens = []; / empty array */
for (i = 0; i < num; i++) { let token = new Token(i, this); /* new variable token = to new token object, loop index and owning player passed here / tokens.push(token); / newly created token added to the tokens array */ }
return tokens; /* array returned after all tokens created */
/gets all tokens that haven't been dropped/ get unusedTokens() { return this.tokens.filter(token => !token.dropped); } }
1 Answer
Steven Parker
231,271 PointsThere should not be an issue with "wrapping" in JavaScript, since whitespace is not significant.
It's hard to tell with unformatted code, since the Markdown seems to have altered the contents a bit; but it looks like you might have an issue with unbalanced braces and/or a stray semicolon between a method declaration and its code block.
In future postings, always format the code in a Markdown code block. Use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. Or watch this video on code formatting.