ES6 - Complete a Promise with resolve and reject

Hello everyone,i need help with something.

1- this is my code block below, and i tried it to run it to the console yet the returned item in the console is an empty curly braces.

Q- What do you think is wrong with my code block.
Note; I am currently practicing completing promise method with resolve and reject method.

const logMyBirthDate  = new Promise((resolve,reject) => {
  
const  myBirthDate = {
first: 2005, _$Second: 7, _Last: 27};

Object.freeze(myBirthDate);

If (myBirthDate.hasOwnProperty(_$Second)) {
resolve(‘myBirthDate object possess _$Second as a property’);
} else {
reject(‘myBirthDate doesn’t possess _$Second as a property’);

});
 
console.log(logMyBirthDate);

MOD EDIT: For reference

There are some syntax errors in your code but, even if you correct those, the code will only log an empty object to the console when it is resolved/rejected.

As your code isn’t specific to the challenge in question, I’ve corrected it and added a then which can be used to log the data received from a resolved promise.

const logMyBirthDate  = new Promise((resolve,reject) => {
  
  const  myBirthDate = {first: 2005, _$Second: 7, _Last: 27};
  Object.freeze(myBirthDate);

  if (myBirthDate.hasOwnProperty('_$Second')) {
    resolve('myBirthDate object possess _$Second as a property');
  } else {
    reject('myBirthDate doesn’t possess _$Second as a property');
  }
});


logMyBirthDate.then((data)=>console.log(data));

More info here:

1 Like