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
87 changes: 87 additions & 0 deletions classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,93 @@ console.log("This is example result: ", fred.task());

// ++++ YOUR ASSIGNMENT STARTS HERE +++++



class GameObject{
constructor(attributes){
this.createdAt = attributes.createdAt
this.name = attributes.name


}


destroy() {
return `${this.name} was removed from the game.`;
}
}

class CharacterStats extends GameObject{
constructor(attributes){
super(attributes)
this.healthPoints = attributes.healthPoints
}

takeDamage() {
return `${this.name} took damage.`;
}
}

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.

/*
=== GameObject ===
Expand Down
48 changes: 47 additions & 1 deletion prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,50 @@
// Move the "Speak" method outside of the constructor function and into the prototype.
// Create an object named "Me" using the "Person" constructor function
// Call the "Speak" method on the "Me" object
// Console log all your results
// Console log all your results





function Person(attr){

this.name = attr.name,
this.age = attr.age,
this.hoppy = attr.hoppy


}

Person.prototype.speak = function(){
return ` magcyku waa ${this.name} waxana ka hilaa ${this.hoppy}`

}


const Me = new Person({
name : 'xaan',
age : 20,
hoppy : 'fotball'
})

console.log(Me.speak())




const Prother = new Person({
name : 'maxmed',
age : 10,
hoppy : 'basketball'
})

const Sister = new Person({
name : 'asmo',
age : 17,
hoppy : 'watching films'
})

console.log(Sister.speak())