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
Reference
この問題について(JS 100第12題:ゲームキャラクタークラスの作成), 我々は、より多くの情報をここで見つけました https://velog.io/@0seo8/JS100제-문제12-게임-캐릭터-클래스-만들기テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol