promise-it-wont-hurt icon indicating copy to clipboard operation
promise-it-wont-hurt copied to clipboard

Exercise 8

Open JavierMendozaGomez opened this issue 8 years ago • 2 comments

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 callsattachTitle then calls console.log.

If your program runs successfully, it should print out “DR. MANHATTAN” which is extremely exciting.

My code:

3

The response 2

thanks for reading me

JavierMendozaGomez avatar Jan 02 '17 19:01 JavierMendozaGomez

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.

robbiedhickey avatar Feb 12 '17 19:02 robbiedhickey

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.

senpl avatar Sep 24 '18 09:09 senpl