JS 100第12題:ゲームキャラクタークラスの作成


質問12:ゲームキャラクタクラスの作成
次のソースコードにクラスを作成して、ゲームキャラクタのコンピテンシー値と火の玉を出力してください.
指定したソースコードは変更できません.
**데이터**
<여기에 class를 작성하세요.>

const x = new Wizard(545, 210, 10);
console.log(x.health, x.mana, x.armor);
x.attack();

**출력**
545 210 10
파이어볼
私の間違った答え
class Wizard {
  constructor(health, mana, armor){
    this.health = health;
    this.mana = mana;
    this.armor = armor;
    this.attack = '파이어볼';
  }
}
正解
const Wizard = class Wizard {
    constructor (health, mana, armor){
        this.health = health;
        this.mana = mana;
        this.armor = armor;
    }
    attack(){
        console.log('파이어볼');
    }
}
classclassは、オブジェクト向けプログラミングにおいて特定のオブジェクトを作成するために変数およびメソッドを定義するフレームワークであり、オブジェクトを定義するためのステータス(メンバー変数)およびメソッド(関数)から構成される.
class User {
  constructor(name) {
    this.name = name;
  }

  sayHello() {
    console.log(this.name)
  }
}

let user = new User("youngseo");
user.sayHello() //yougseo