I have a question about how things are returned.
Instead of console.log() I wanted to return Oh powerful…`, but then only
Oh powerful Blorgous…
is outputted.
Nothing more. Also, I wanted to use this:
phrase = `Oh powerful...`
and then return it, but only
Oh powerful SpaceKing…
is outputted.
But when I just console.log() every name, it works. Why?
const greetAliens = (arr) => {
let phrase = '';
for (let i = 0; i < arr.length; i++) {
/*
a good thing to notice:
if we used just return `Oh powerful...`, then only `Oh powerful Blorgous...` would be returned.
if we used phrase = `Oh powerful...` and then returned it, only 'Oh powerful SpaceKing..` would be returned.
*/
console.log(`Oh powerful ${arr[i]}, we humans offer our unconditional surrender!`);
}
}
greetAliens(["Blorgous", "Glamyx", "Wegord", "SpaceKing"]);
/*
Oh powerful Blorgous, we humans offer our unconditional surrender!
Oh powerful Glamyx, we humans offer our unconditional surrender!
Oh powerful Wegord, we humans offer our unconditional surrender!
Oh powerful SpaceKing, we humans offer our unconditional surrender!
*/