Recap Challenge
Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 20 of 56.
Challenge
You're given a GameCharacter class. Your task is to:
- Add a private field
#isAliveinitialized totrue - Add a private method
#checkIfAlive()that:- Sets
#isAlivetotrueif#health > 0 - Sets
#isAlivetofalseif#health ≤ 0
- Sets
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
1Objects & The this Keyword
Quick Review: ObjectsAdding Methods to ObjectsUnderstanding the this KeywordConstructor FunctionsThe new KeywordRecap Challenge7 Inheritance & The extends Key
InheritanceThe "is-a" RelationshipThe extends KeywordThe super() MethodInheriting Properties&MethodsRecap Challenge2Organizing Code
What are Modules?Exporting with exportImporting with importDefault vs. Named Exports8Organizing OOP Code
Organize Classes into Modules11Project: A Shape Renderer
Setup: Shape Class & ExportCircle Class Inheritance9Static Methods & Properties
Class-Level vs. Instance-LevelStatic PropertiesStatic Utility MethodsRecap challenge