Game Character Builder
Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 53 of 56.
Challenge
This is a simple game character system where characters can equip weapons and engage in combat.
Your task is to add these two methods to the Character class:
Method 1: takeDamage(amount)
- This method reduces the character's health by the amount
- Logs:
${this.name} takes ${amount} damage
Method 2: equipWeapon(weapon)
- This method gives the character a weapon (composition: "has-a" relationship)
- Logs:
${this.name} equipped ${weapon.name}
Try it yourself
import { Character } from './character.js';
import { Weapon } from './weapon.js';
const hero = new Character('Knight');
const sword = new Weapon('Sword', 10);
hero.equipWeapon(sword); // Should log: "Knight equipped Sword"
hero.takeDamage(20); // Should log: "Knight takes 20 damage"
console.log(hero.health); // Should show: 80All 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 challenge12Getters & Setters
The get and set KeywordsComputed PropertiesValidation and Side EffectsRecap Challenge15 Final Challenges
Game Character BuilderE-commerce Product SystemUniversity Management SystemSmart Home Device System