Menu
Coddy logo textTech

복습 챌린지

Coddy JavaScript 여정의 객체 지향 프로그래밍 섹션에 포함된 레슨 — 56개 중 20번째.

challenge icon

챌린지

GameCharacter 클래스가 주어집니다. 당신의 과제는 다음과 같습니다:

  1. true로 초기화된 프라이빗 필드 #isAlive를 추가합니다.
  2. 다음 기능을 수행하는 프라이빗 메서드 #checkIfAlive()를 추가합니다:
    • #health > 0이면 #isAlivetrue로 설정합니다.
    • #health ≤ 0이면 #isAlivefalse로 설정합니다.

직접 해보기

import { GameCharacter } from './GameCharacter.js';

// 테스트 코드 - 수정하지 마세요
const warrior = new GameCharacter("Warrior");

warrior.takeDamage(30);
console.log(warrior.getStatus());  // "Alive"가 출력되어야 함

warrior.takeDamage(80);
console.log(warrior.getStatus());  // "Defeated"가 출력되어야 함

객체 지향 프로그래밍의 모든 레슨