0

Just curious as to why its not printing both peter.attack() and kegann.attack() in the console.

console for this function:

"attacks with fire"

function createElf(name, weapon) {
    return {

        name,
        weapon,
        attack(){
            return 'attack with ' + weapon

        }
    }
}

const peter = createElf('Peter', 'stones')
peter.attack();

const kegann = createElf('Sam', 'fire')
kegann.attack();
Mugs
  • 339
  • 3
  • 14
  • 4
    Because when you run a script in the console, it always only prints the result of the last statement. If you want to print other/more things, use `console.log`. (If it would implicitly log the result of every function call, it would be quite a mess) – Bergi Sep 20 '19 at 00:04
  • @Bergi Oh wow. I had no idea lol. Thank you. – Mugs Sep 20 '19 at 00:05

0 Answers0