What's the correct way to log error to the console

// running tests You should log

error

to the console. // tests completed

const makeServerRequest = new Promise((resolve, reject) => {
  let responseFromServer = false;
  if(responseFromServer) {
    resolve("We got the data");
  } else {  
    reject("Data not received");
    }
});
makeServerRequest.then(result => {

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

I would expect to see something like this:

const makeServerRequest = new Promise((resolve, reject) => {
  const responseFromServer = false;
  if (responseFromServer) {
    resolve("We got the data");
  } else {
    reject("Data not received");
  }
});

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

First of all, the log has to be in the right code block. And I think you want to chain those.

1 Like

The code is still not passed the test, but Iā€™m trying to fix it

This worked.

const makeServerRequest = new Promise((resolve, reject) => {
  const responseFromServer = false;
  if (responseFromServer) {
    resolve("We got the data");
  } else {
    reject("Data not received");
  }
});

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

And thank you so much for the contribution

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.