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

Objects within objects in JavaScript

I am currently practising how to declare multiple objects within other objects, however, I am struggling to understand where I have gone wrong. The code provided below is what I used and it is just a random collection of variables. Once put through the chrome browser console, it returns an error for line 21 that declares a generate object within the myObj. The error says: "Uncaught syntax error: Unexpected Identifier".

let myObj = {


    module: {

        color: 'red',
        dimensionX: 230,
        dimensionY: 330,
        hasBorder:  false,
        currentSpecs: ['mod1', 'mod2', 'mod3', 'mod4', 'mod5', 'mod6', 'mod7' ],
        points: 1240,
        bonusPoints: 200,
        multiplier: 2.5,
        score: function(){

            return (this.points + this.bonusPoints) * this.multiplier;  

        }
    }

    generateEnemy: {

        enemyTypes: 13,
        enemyClans: [

            ['covenant', 'red', 4, 'average', true],
            ['pedants', 'green', 1, 'strong', true],
            ['floods', 'yellow', 3, 'strong', false],
            ['rodies', 'orange', 2, 'weak', false], 
            ['probear', 'blue', 3, 'strong', false]

        ],

        enemySpawns: true

    }


}

1 Answer

It looks like it wants a comma after your closing bracket for Module.