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
153 changes: 153 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,154 @@
// CODE here for your Lambda Classes
class Person{
constructor(attributes){
this.name = attributes.name;
this.age = attributes.age;
this.location = attributes.location;
this.gender = attributes.gender;
}
speak() {
console.log(`Hello my name is ${this.name}, I am from ${this.location}`);
}
}

class Instructor extends Person {
constructor(attributes){
super(attributes)
this.specialty = attributes.specialty;
this.favLanguage = attributes.favLanguage;
this.catchPhrase = attributes.catchPhrase;
}
demo(subject) {
console.log(`Today we are learning about ${subject}`);
}
grade(student, subject) {
let randNum = Math.floor(Math.random()*3);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try and keep your code DRY. You are using - Math.floor(Math.random() ); in 3 different places inside one function. maybe you can create a function?

if(randNum === 0){
let points = Math.floor(Math.random()*11);
student.score -= points;
console.log(`You have to work on ${subject}. I have to remove ${points} points from your score. You have only ${student.score} left.`)
} else if (randNum === 1 || randNum === 2) {
let points = Math.floor(Math.random()*11);
student.score += points;
console.log(`Great work on ${subject}. I add ${points} points to your score. You have now ${student.score} points.`);
}
}

}

class Student extends Person {
constructor(attributes){
super(attributes);
this.score = Math.floor(Math.random()*100);
this.previousBackground = attributes.previousBackground;
this.className = attributes.className;
this.favSubjects = attributes.favSubjects;
}
listsSubjects(){
for (let i = 0; i < this.favSubjects.length; i++){
console.log(this.favSubjects[i]);
}
}
PRAssignment(subject){
console.log(`${this.name} has submitted a PR for ${subject}.`);
}
sprintChallenge(subject){
console.log(`${this.name} has begun sprint challenge on ${subject}.`);
}
graduate(){
if(this.score >= 70){
console.log(`Good job, ${this.name}. You perfected the art of clicking your keyboard wile sitting in a dark room. Here is your black hoodie!`)
} else {
console.log(`Sorry ${this.name}. You are not ready. Go back in your dark room and try to type faster.`)
}
}

}

class ProjectManager extends Instructor {
constructor(attributes){
super(attributes);
this.gradClassName = attributes.gradClassName;
this.favInstructor = attributes.favInstructor;
}
standUp(channel){
console.log(`${this.name} announces to ${channel}, @channel standy time!`);
}
debugsCode(student, subject){
console.log(`${this.name} debugs ${student.name}'s code on ${subject}.`)
}
}

const Mark = new Instructor({
name: 'Mark',
age: 20,
location: 'Paris',
gender: 'Male',
specialty: 'React',
favLanguage: 'Python',
catchPhrase: 'If you want more ram, just download it.'
});

const Sean = new Instructor({
name: 'Sean',
age: 26,
location: 'Tokyo',
gender: 'Male',
specialty: '',
favLanguage: 'C++',
catchPhrase: 'Did you try to restart your pc?'
});

const John = new Instructor({
name: 'John',
age: 32,
location: 'Seoul',
gender: 'Female',
specialty: 'Redux',
favLanguage: 'JavaScript',
catchPhrase: 'If you want more ram, just download it.'
});

const Tim = new Student({
name: 'Tim',
age: 26,
location: 'Berlin',
gender: 'Male',
previousBackground: 'owned a own company',
className: 'WEBEU1',
favSubjects: ['Less', 'React', 'Redux']
});

const Max = new Student({
name: 'Max',
age: 32,
location: 'Dublin',
gender: 'Female',
previousBackground: 'Studied economics',
className: 'WEBEU1',
favSubjects: ['CSS', 'HTML5', 'React']
});

const Samar = new ProjectManager({
name: 'Samar',
age: 32,
location: 'Dheli',
gender: 'Male',
specialty: 'React',
favLanguage: 'JavaScript',
catchPhrase: 'If you have windows, you\'re doomed',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amen!

gradClassName: 'WEBEU1',
favInstructor: 'Gabriel'
});

const Oliver = new ProjectManager({
name: 'Oliver',
age: 32,
location: 'London',
gender: 'Male',
specialty: 'Python',
favLanguage: 'C++',
catchPhrase: 'If you have apple, you\'re doomed',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not true.

gradClassName: 'WEBEU1',
favInstructor: 'Tom'
});
118 changes: 118 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,121 @@ 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.dimensions = attributes.dimensions;
}
destroy(){
return `${this.name} was removed from the game`;
}
}
/*
=== CharacterStats ===
* healthPoints
* name
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/
class CharacterStats extends GameObject{
constructor(attributes){
super(attributes);
this.healthPoints = attributes.healthPoints;
this.name = attributes.name;
}
takeDamage(){
return `${this.name} took damage`;
}
}



/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
* team
* weapons
* language
* greet() // prototype method -> returns the string '<object name> offers a greeting in <object language>.'
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/
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}`
}
}
/*
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
* Instances of CharacterStats should have all of the same properties as GameObject.
*/

// Test you work by un-commenting these 3 objects and the list of console logs below:


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.