Exercise 2... can I get a hint?
Opened this issue · 2 comments
I remember when I was learning callbacks, they totally baffled me. Now I find them so easy, it's hard to remember how hard they were. Now promises baffle me.
The second exercise gives a decent explanation of how the flow works. But the boilerplate at the bottom just isn't enough. I am completely lost. I've never written a promise before.
I think after doing this exercise, I can build on that knowledge and the rest will not be as hard. But for right now, I have to cheat and look up the answer.
Tl;dr: A hint in exercise 2 would go a long way.
OK, I see. I understood that I needed fulfill('FULFILLED');
in the promise definition, but I was trying to avoid the callback in setTimetout()
!
I could have guessed that, but I could never have guessed the runtime. I tried console.log(promise)
. I guess I'm just not used to calling console.log()
without an argument!
I get it now... gonna study this code and take it from there.
Firstly, you should use newlines. It makes it hard to read, and you missed a semicolon.
Here are some hints:
fulfill()
is only available in the promise constructor, not thethen
function- Use
console.log
in thethen
function, not the promise constructor
var promise = new Promise(function (fulfill, reject) {
setTimeout(function() {
console.log('FULFILLED!'); // don't use console.log here
}, 300); // Missing semicolon
})
.then(() => {
fulfill('FULFILLED'); // don't use fulfill() here
console.log(fulfill(setTimeout)); // or here
});
Here's another one, because promises are hard:
.then((valueFromFulfilledPromise) => {