diff --git a/assignments/index.html b/assignments/index.html index 2fc751cde..1a4108a23 100644 --- a/assignments/index.html +++ b/assignments/index.html @@ -7,11 +7,11 @@ JS IV - + - +small change

JS IV - Check your work in the console!

\ No newline at end of file diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..1a7e91170 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,166 @@ // CODE here for your Lambda Classes + + +class Person { + constructor(attributes){ + this.name = attributes.name + this.gender = attributes.gender + this.age = attributes.age + this.location = attributes.location + } + speak() { + return `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 going to be learning about ${subject}`) + } + grade(student, subject){ + //create a random grade number. + let randomNum = Math.floor(Math.random() * 10); + if(randomNum > 5){ + randomNum *= 1; + } else { + randomNum *= -1 + } + //check if grade to make sure grade doesnt go over 100 + if((student.grade + randomNum) > 100 ){ + student.grade = 100 + } else { + student.grade += randomNum + } + console.log(`${student.name} recieves a score of ${randomNum} on ${subject} and now has a ${student.grade}`) + } +} + +class Student extends Person{ + constructor(attributes){ + super(attributes) + this.previousBackground = attributes.previousBackground + this.className = attributes.className + this.favSubjects = attributes.favSubjects + this.grade = attributes.grade + } + listSubjects(){ + this.favSubjects.forEach(subject => console.log(subject)) + } + PRAssignment(subject){ + console.log(`${this.name} has submitted a pull request for ${subject}`) + } + sprintChallenge(subject){ + console.log(`${this.name} has begun a sprint challenge for ${subject}`) + } + graduate(){ + if(this.grade < 70){ + console.log(`Unfortunately ${this.name} has a grade of ${this.grade}. ${this.name} may not graduate at this time`) + } else { + console.log(`We are pleased to announce that ${this.name} has graduated from the school with a grade of ${this.grade}`) + } + } +} + +class ProjectManager extends Instructor{ + constructor(attributes){ + super(attributes) + this.gradClassName = attributes.gradClassName + this.favInstructor = attributes.favInstructor + } + standUp(slack){ + console.log(`${this.name} announces ${slack}, @channel study times!`) + } + debugsCode(student, subject){ + console.log(`${this.name} debugs ${student.name}'s code on ${subject}`) + } +} + +//NEW INSTRUCTORS fred and jane + +const fred = new Instructor({ + name: 'Fred', + location: 'Bedrock', + age: 37, + gender: 'male', + favLanguage: 'JavaScript', + specialty: 'Front-end', + catchPhrase: `Don't forget the homies` + }); + +const jane = new Instructor({ + name: 'Jane', + location: 'New Orleans', + age: 32, + gender: 'female', + favLanguage: 'Python', + specialty: 'Databases', + catchPhrase: `If its a number, I can add it` +}); + +//New Students blake and Jasmine + +const blake = new Student({ + name: 'Blake', + location: 'Little Rock', + age: 22, + gender: 'Male', + previousBackground: 'Roof Sweeper', + className: 'FSW PT2', + favSubjects: ['Gardening', 'Herbology', 'Alchemy'], + grade: 65 + }); + +const jasmine = new Student({ + name: 'Jasmine', + location: 'Little Rock', + age: 22, + gender: 'female', + previousBackground: 'dishwasher', + className: 'FSW Fulltime 4', + favSubjects: ['Math', 'English', 'Grammer'], + grade: 100 + }); + + //NEW PROJECT MANAGERS MARGO AND CARLOS + + const margo = new ProjectManager({ + name: 'Margo', + location: 'Eastville', + age: 36, + gender: 'female', + favLanguage: 'JavaScript', + specialty: 'Front-end', + catchPhrase: `Keep on keeping on`, + gradClassName: `FSW FT1`, + favInstructor: 'Jane' + }); + +const carlos = new ProjectManager({ + name: 'Carlos', + location: 'Brookton', + age: 29, + gender: 'male', + favLanguage: 'JavaScript', + specialty: 'Back-end', + catchPhrase: `Hustle till you drop`, + gradClassName: `FSW PT1`, + favInstructor: 'Fred' + }); + + + console.log(fred.speak()) + console.log(jasmine.speak()) + console.log(jasmine.sprintChallenge('math')) + console.log(margo.debugsCode(jasmine, 'math')) + + //stretch task with grades + fred.grade(blake,'math') + blake.graduate() + fred.grade(jasmine,'math') + jasmine.graduate() \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..3915df3c9 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,193 @@ 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. */ + +/* + Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several constructor functions with their correct inheritance hierarchy. + + In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid. + + At the bottom of this file are 3 objects that all end up inheriting from Humanoid. Use the objects at the bottom of the page to test your constructor functions. + + Each constructor function has unique properties and methods that are defined in their block comments below: +*/ + +/* + === GameObject === + * createdAt + * dimensions (These represent the character's size in the video game) + * destroy() // prototype method -> returns the string: 'Object was removed from the game.' +*/ + +class GameObject { + constructor(attributes){ + this.createdAt = attributes.createdAt + 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}`; + } +} + + // 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. + + class Villain extends Humanoid { + constructor(attributes){ + super(attributes) + } + attack(target){ + target.healthPoints -= 7 + console.log(`${this.name} attacks ${target.name} for 7 HP`) + + if(target.healthPoints <= 0){ + return target.destroy() + } + return `${target.name} is now at ${target.healthPoints} health`; + } + } + + class Hero extends Humanoid { + constructor(attributes){ + super(attributes) + } + heal(target){ + target.healthPoints += 15 + console.log(`${target.name} is now ${target.healthPoints}`) + return `${this.name} heals ${target.name} for 15 HP`; + } + } + +//new Hero + const goodMan = new Hero({ + createdAt: new Date(), + dimensions: { + length: 1, + width: 2, + height: 4, + }, + healthPoints: 10, + name: 'Priest', + team: 'Good Boy Street', + weapons: [ + 'Staff', + 'Cross', + ], + language: 'Latin', + }); + +// New Villain + const evilMan = new Villain({ + createdAt: new Date(), + dimensions: { + length: 1, + width: 2, + height: 4, + }, + healthPoints: 10, + name: 'Blake', + team: 'Bad Boy Street', + weapons: [ + 'Poison', + 'Dagger', + ], + language: 'Gibberish', + }); + + // * 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! + + console.log(evilMan.attack(archer)); + console.log(goodMan.heal(archer)); + console.log(evilMan.attack(archer)); + console.log(evilMan.attack(archer)); + console.log(evilMan.attack(archer)); + //"Lilith was removed from the game" \ No newline at end of file