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

Aaron Thomas
seal-mask
.a{fill-rule:evenodd;}techdegree
Aaron Thomas
Full Stack JavaScript Techdegree Student 13,189 Points

nothing happens when I run "node Pet.js"

here is my code....

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

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

and this is the response...

treehouse:~/workspace$ node Pet.js
treehouse:~/workspace$

3 Answers

Nothing happened because you didn't log the output to the console, so node didn't show you the results. You need to console.log(ernie) at the end of your code. Happy coding!

Steven Parker
Steven Parker
231,269 Points

This code doesn't try to output anything (as might be done with a console.log statement), so everything appears to be working. When you give the command, node executes the code, and it runs without errors, and when it is complete node exits and you get another system prompt.

Julieta Dalla Pozza
Julieta Dalla Pozza
4,337 Points

Me i have put the output in console.log and nothing seem to be happen

const ernie = { animal: 'dog', age: '1', breed: 'pug', bark: function(){ console.log('Woof!'); } }

console.log(ernie.age); console.log(ernie.breed);

treehouse:~/workspace$ node pets.js
treehouse:~/workspace$ pets.js
bash: pets.js: command not found
treehouse:~/workspace$

Steven Parker
Steven Parker
231,269 Points

Did you remember to save your changes in the editor before giving the command to run it?