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
1 change: 1 addition & 0 deletions assignments/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@

<body>
<h1>JS IV - Check your work in the console!</h1>
<h2>Start</h2>
</body>
</html>
105 changes: 104 additions & 1 deletion assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,110 @@
Prototype Refactor

1. Copy and paste your code or the solution from yesterday

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 (data2){
this.createdAt = data2.createdAt;
this.dimensions = data2.dimensions;
}
destroy (){
return `${this.name} was removed from game`
}
}



class CharacterStats extends GameObject {
constructor(characterStatsData){
super(characterStatsData);
this.hp = characterStatsData.hp;
this.name = characterStatsData.name;
}
tookDamage(){
return `${this.name} took damage.`;
}
}

class Humanoid extends CharacterStats {
constructor(humanoidData) {
super(humanoidData)
this.team = humanoidData.team;
this.weapons = humanoidData.weapons;
this.language = humanoidData.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.