Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
2 changes: 1 addition & 1 deletion assignments/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
</head>

<body>
<h1>JS IV - Check your work in the console!</h1>
<p>Run Console</p>
</body>
</html>
97 changes: 97 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,101 @@ Prototype Refactor

2. Your goal is to refactor all of this code to use ES6 Classes. The console.log() statements should still return what is expected of them.


*/

class GameObject {
constructor(attributes) {
this.createdAt = new Date();
// this.name = attributes.name;
this.dimensions = attributes.dimensions;
}
destroy() {
return `${this.name} was removed from the game.`
};
}

class CharacterStats extends GameObject{
constructor(attributes) {
super(attributes);
this.healthPoints = attributes.healthPoints;
this.name = attributes.name;
}
takeDamage() {
return `${this.name} took damage.`
};
}

class Humanoid extends CharacterStats {
constructor(attributes) {
super(attributes);
this.team = attributes.team;
this.weapons = attributes.weapons;
this.language = attributes.language;
}
greet() {
return `${this.name} offers a greeting in ${this.language}.`
};
}

const mage = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 2,
width: 1,
height: 1,
},
healthPoints: 5,
name: 'Bruce',
team: 'Mage Guild',
weapons: [
'Staff of Shamalama',
],
language: 'Common Tongue',
});

const swordsman = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 2,
width: 2,
height: 2,
},
healthPoints: 15,
name: 'Sir Mustachio',
team: 'The Round Table',
weapons: [
'Giant Sword',
'Shield',
],
language: 'Common Tongue',
});

const archer = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 1,
width: 2,
height: 4,
},
healthPoints: 10,
name: 'Lilith',
team: 'Forest Kingdom',
weapons: [
'Bow',
'Dagger',
],
language: 'Elvish',
});

console.log(mage.createdAt); // Today's date
console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }
console.log(swordsman.healthPoints); // 15
console.log(mage.name); // Bruce
console.log(swordsman.team); // The Round Table
console.log(mage.weapons); // Staff of Shamalama
console.log(archer.language); // Elvish
console.log(archer.greet()); // Lilith offers a greeting in Elvish.
console.log(mage.takeDamage()); // Bruce took damage.
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.