ES6: Complete a Promise with resolve and reject

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/complete-a-promise-with-resolve-and-reject
What is the reason why this is not working



const makeServerRequest = new Promise((resolve, reject) => {
  // responseFromServer represents a response from a server
  let responseFromServer=a;
    
  if(responseFromServer===a) {
    // change this line
    resolve("We got the Data");
  } else {  
    // change this line
    reject("Data not Received");
  }
});


What represents value a inside
responseFromServer ?

You should put a boolean either true or false to responseFromServer,and that should be used inside if else blocks.

Also,inside reject(),Data not Received - received should be written in lowercase.
Hope this helps! :slight_smile:

I think that it is boolean, isn´t it?

const makeServerRequest = new Promise((resolve, reject) => {
  // responseFromServer represents a response from a server
  let responseFromServer=5;
    
  if(responseFromServer>3) {
    // change this line
    resolve("We got the Data");
  } else {  
    // change this line
    reject("Data not Received");
  }
});

Read carefully

Make the promise handle success and failure. If responseFromServer is true

You use boolean inside if or else block,but first,you have to make responseFromServer to be true,because it is said from the challenge,not passing numbers.

Also,be careful when passing strings inside resolve() and reject(), text should be the same as challenge is saying.

1 Like

I have done. Thanks!!!

1 Like