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 Object-Oriented JavaScript Working with Classes in JavaScript Instantiating a Pet Object

Hanna Zeif
Hanna Zeif
11,309 Points

Nothing happens

My code looks identical to what's on the screen but it's not doing anything. When I type "node Pet.js into the console it just gives me another line in the console, no output. Here's my code:

class Pet { constructor(animal, age, breed) { this.animal = animal; this.age = age; this.breed = breed; } }

const ernie = new Pet('dog', 1, 'pug');

const vera = new Pet('dog', 8, 'border collie');


4 Answers

I was having this same problem because I wasn't paying attention when she added the console.log(ernie) portion and the view later is scrolled up. :)

Make sure to save the Pet.js document (command S or control S). It might just be you haven't saved the recent changes you just added then nothing happens because nothing has been saved yet.

Marcos Velasco
Marcos Velasco
3,298 Points

I would recommend installing node.js and using Visual Studio code since you would have to use it in the future anyways.

I copied your code and pasted it into the workspace, it looks like it is working fine: link to image