promise-it-wont-hurt
promise-it-wont-hurt copied to clipboard
Exercise 8
HI i got this problem with the execution of exercise 8:
The Task
Construct a promise chain that returns values to prove to yourself that promise handlers will wrap your returned values in promises allowing additional chaining.
- Declare a function
attachTitle
which prepends'DR. '
to its firstargument and returns the result. - Create a fulfilled promise with a value of
'MANHATTAN'
. - Build a promise chain off the promise we just constructed that first calls
attachTitle
then callsconsole.log
.
If your program runs successfully, it should print out “DR. MANHATTAN” which is extremely exciting.
My code:
The response
thanks for reading me
This is failing because the workshopper enforces an assumption that the name of the function passed to your first then()
call will be 'attachTitle' (it uses the name
property of the function to determine this). In your case, you are using an anonymous function expression and assigning to a variable named attachTitle, so the 'name' property will be empty. You should be able to fix this with a function declaration or named function expression:
// function declaration
function attachTitle(word) {
return 'DR. ' + word;
}
// named function expression
var attachTitle = function attachTitle(word) {
return 'DR. ' + word;
}
There is another scenario in this issue that reports a false negative for a similar reason: https://github.com/nodeschool/discussions/issues/2002
CC @TimothyGu - any thoughts on how to mitigate these false negatives? Looking at the code it is not obvious to me how we could handle these scenarios without removing the check.
I do not understand why this is incorrect
.then(val => attachTitle(val)).then(console.log);
but this is correct
.then(attachTitle).then(console.log);
They seems that same one is just shorter.