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 Practice Getters and Setters in JavaScript Practicing Getters and Setters Practice Creating and Accessing a Getter method

Frustrated... even when I copied and pasted the solution for # 1... I got an error. Bummer: Unexpected identifier

I had tried everything, so out of desperation, I copied and pasted the solution for Challenge 1. and I got the same error... Bummer: Unexpected identifier. THIS is why I'm not sure I'm gonna make it... there's a problem and I can't find it.

Rectangle.js
class Rectangle {
    constructor(width, length){
        this.width = width;
        this.length = length;
    }
}

get area() {
    return this.width * this.length;
}

const rect1 = new Rectangle(10, 5);
const rect2 = new Rectangle(6, 12);
const rect3 = new Rectangle(15, 20);

2 Answers

The getter method should be inside the class.

so... I did this:

class Rectangle {
    constructor(width, length){
        this.width = width;
        this.length = length;
    }
    get area() {
    return this.width * this.length;
}

const rect1 = new Rectangle(10, 5);
const rect2 = new Rectangle(6, 12);
const rect3 = new Rectangle(15, 20);

AND

class Rectangle {
    constructor(width, length){
        this.width = width;
        this.length = length;

get area() {
    return this.width * this.length;
    }
}

const rect1 = new Rectangle(10, 5);
const rect2 = new Rectangle(6, 12);
const rect3 = new Rectangle(15, 20);

Same error.

found the problem.... thanks for looking!