Why does my JavaScript code logs undefined to the console?

Hello There!

I am working on objects on codecademy. Plz someone tell me why my code prints undefined two times?

here’s my js code -


let retreatMessage = ‘We no longer wish to conquer your planet. It is full of dogs, which we do not care for.’;

// Write your code below

let alienShip = {
retreat: function () {
console.log(retreatMessage)
}, takeOff: function () {
console.log(‘Spim… Borp… Glix… Blastoff!’)
}
};

console.log(alienShip.retreat());
console.log(alienShip.takeOff());


Any help would be appreciated!

your methods do not return anything. Yet, when you call the methods:

console.log(alienShip.retreat());
console.log(alienShip.takeOff());

you attempt to .log() the returned result, which gives undefined

also, if you are using es6 you can write methods with the following shorter syntax:

retreat() {
   // 
}
3 Likes

Thanks a lot sir…