Menu
Coddy logo textTech

Recap Challenge

Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 20 of 56.

challenge icon

Challenge

You're given a GameCharacter class. Your task is to:

  1. Add a private field #isAlive initialized to true
  2. Add a private method #checkIfAlive() that:
    • Sets #isAlive to true if #health > 0
    • Sets #isAlive to false if #health ≤ 0

Try it yourself

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

// Test code - don't modify
const warrior = new GameCharacter("Warrior");

warrior.takeDamage(30);
console.log(warrior.getStatus());  // Should output "Alive"

warrior.takeDamage(80);
console.log(warrior.getStatus());  // Should output "Defeated"

All lessons in Object Oriented Programming