Handle a Fulfilled Promise with then

Directions for this challenge say:
Add the then method to your promise. Use result as the parameter of its callback function and log result to the console.

Here’s the code with my code marked //my code:

  let responseFromServer = true;
  if(responseFromServer) {
    resolve("We got the data");
  } else {  
    reject("Data not received");
  }
  makeServerRequest.then(result => {//my code
    console.log(result);//my code
  })//my code
});```

The code passes the test but nothing is logged to the console.

What challenge is this? Can we see the rest of the code?

Shouldn’t it be calling makeServerRequest (i.e. call it using parenthesis).

The challenge is:
ES6: Handle a Fulfilled Promise with then
Here’s the starter code:

const makeServerRequest = new Promise((resolve, reject) => {
  // responseFromServer is set to true to represent a successful response from a server
  let responseFromServer = true;
    
  if(responseFromServer) {
    resolve("We got the data");
  } else {  
    reject("Data not received");
  }
});

Most likely a limitation of the fCC console. If you open the browser console (F12) you should see it logging “We got the data”.

You didn’t post your full code so it’s a bit hard to tell. However this…

makeServerRequest.then(result => {
  console.log(result);//my code
})

…can’t be inside the Promise. It needs to be outside it, or you need to use .then() directly on the Promise.

const makeServerRequest = new Promise((resolve, reject) => {
...code
}).then(result => {
  console.log(result);
})
1 Like