Code without makeSeverRequest

code without makeSeverRequest work too.

makeServerRequest

const makeServerRequest = new Promise((resolve, reject) => {

  // responseFromServer is set to false to represent an unsuccessful response from a server

  let responseFromServer = false;

    

  if(responseFromServer) {

    resolve("We got the data");
  } else {  
    reject("Data not received");
  }

})
.then(result => {  console.log(result);})
.catch(error => {  console.log(error)})

Do you have a question?

Not really sure what you are asking here? You are directly dotting on to the return and doing so you don’t have to use makeServerRequest. But you can use it though.

const makeServerRequest = new Promise((resolve, reject) => {
  // responseFromServer is set to false to represent an unsuccessful response from a server

  let responseFromServer = false;

  if (responseFromServer) {
    resolve("We got the data");
  } else {
    reject("Data not received");
  }
});

makeServerRequest
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.log(error);
  });

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.

markdown_Forums