From 5cc925e1fce5d1f00c35433b9e8b79ae5d56826e Mon Sep 17 00:00:00 2001 From: Aasa-Christian Date: Thu, 19 Sep 2019 16:28:51 -0400 Subject: [PATCH] completed MVP --- .vscode/settings.json | 3 + assignments/lambda-classes.js | 90 ++++++++++++++++++++++++++ assignments/prototype-refactor.js | 104 ++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..6f3a2913e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..0751f6070 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,91 @@ // CODE here for your Lambda Classes +'use strict'; +class Person{ + constructor(atts){ + this.name = atts.name + this.age = atts.age, + this.location = atts.location; + } + speak(){ + return `Hello my name is ${this.name}, I am from ${this.location}.` + } +} + +class Instructor extends Person{ + constructor(attr){ + super(attr); + this.specialty = attr.specialty, + this.favLanguage = attr.favLanguage, + this.catchPhrase = attr.catchPhrase; + } + demo(){ + this.subject = attr.subject, + `Today we are learning about ${this.subject}` + } + grade(){ + this.student = attr.student, + `${this.student} receives a perfect score on ${this.subject}` + } +} + +class Student extends Person{ + constructor(attx){ + super(attx); + this.previouseBackground = attx.previouseBackground, + this.className = attx.className, + this.favSubjects = attx.favSubjects; + this.prSubject = attx.prSubject, + this.sprintSubject = attx.sprintSubject + } + listSubjects(){ + return(this.favSubjects) + } + PRAssignment(){ + return(`${this.name} has submitted a PR for ${this.prSubject}.`) + } + sprintChallenge(){ + return (`${this.name} has begun sprint challenge on ${this.sprintSubject}.`) + } +} + +class ProjectManager extends Instructor{ + constructor(attz){ + super(attz); + this.gradClassName = attz.gradClassName, + this.favInstructor = attz.favInstructor, + this.channel = attz.channel, + this.studentName = attz.studentName, + this.subject = attz.subject; + + }; + standUp(){ + return(`${this.name} announces to ${this.channel}, @channel standy times!`) + } + debugsCode(){ + return(`${this.name} debugs ${this.studentName}'s code on ${this.subject}.`) + } + +} + +const aasa = new Student({ + name: 'Aasa', + age: 30, + location: 'Virginia', + previouseBackground: 'Doctor', + className: "Web24", + favSubjects: 'math, science, english', + prSubject: 'JavaScript IV', + sprintSubject: 'Advanced CSS' + +}); + +const tom = new ProjectManager({ + name: 'Thomas', + studentName: 'Aasa', + subject: 'advanced CSS' + +}); + +console.log(aasa.favSubjects) +console.log(aasa.sprintChallenge()) +console.log(tom.debugsCode()) \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..bde0c5bbf 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,107 @@ 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(attr){ + this.createdAt = attr.createdAt, + this.name = attr.name, + this.dimensions = attr.dimensions + } + destroy(){ + return (`${this.name} was removed from the game.`); + }; +} + + class CharacterStats extends GameObject{ + constructor(atts){ + super(atts); + this.healthPoints = atts.healthPoints; + } + takeDamage(){ + return(`${this.name} took damage`); + + }; + } + + class Humanoid extends CharacterStats{ + constructor(attx){ + super(attx); + this.team = attx.team, + this.weapons = attx.weapons, + this.language = attx.language + } + greet(){ + return (`${this.name} offers a greeting in ${this.language}.`); + }; + } + + // 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. + + + // Stretch task: + // * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function. + // * Give the Hero and Villains different methods that could be used to remove health points from objects which could result in destruction if health gets to 0 or drops below 0; + // * Create two new objects, one a villain and one a hero and fight it out with methods! \ No newline at end of file