Programming with Objects
Let's dig out a little more interesting concepts about Objects in JavaScript.
Many books and courses teach object-oriented programming through examples involving animals, cars or bank accounts. Let’s try something cooler and create a mini-role playing game (RPG) using objects. In a role-playing game, each character is defined by many attributes like strength, stamina or intelligence. Here’s the character screen of a very popular online RPG.
Show online RPG manu
In our simpler example, a character will have three attributes:
- her name,
- her health (number of life points),
- her strength.
A naive example
Let me introduce you to Aurora, our first RPG character.
Press + to interact
const aurora = {name: "Aurora",health: 150,strength: 25};
The aurora
object has three properties: name
, health
and strength
.
As you can see, you can assign numbers, strings, and even other objects to properties!
Aurora is about to ...
Access this course and 1400+ top-rated courses and projects.