Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Asynchronous Programming with JavaScript Understanding Promises Create a Promise

Austin Schneider
Austin Schneider
4,919 Points

Terminal says pending, but after changes won't resolve and show message.

Finally got the terminal to say pending, but after adding resolve and breakfastPromise.then() it won't resolve and print the message. Help!

const breakfastPromise = new Promise( (resolve, reject) => {
    setTimeout (() => {
        resolve('Your order is ready. Come and get it!');
    }, 3000);
});

console.log(breakfastPromise);
breakfastPromise.then( val => console.log(val) );

Let me know if you see anything wrong! I've been stuck on this for days. Took me several just to get vs code to run node on promises-breakfast!

2 Answers

Blake Larson
Blake Larson
12,988 Points

I ran it in node and it resolved like it should.

const breakfastPromise = new Promise( (resolve, reject) => {
    setTimeout (() => {
        resolve('Your order is ready. Come and get it!');
    }, 3000);
});

console.log(breakfastPromise);
breakfastPromise.then( val => {
    console.log(val) 
    console.log(breakfastPromise);
});

/////// OUTPUT
$ node app.js  // I just ran it in a quick app.js file
Promise { <pending> }
Your order is ready. Come and get it!
Promise { 'Your order is ready. Come and get it!' }

I had a similar issue, try hitting ctrl+s before running in the console, that seemed to solve it for me