diff --git a/assignments/code.js b/assignments/code.js new file mode 100644 index 000000000..f00ade769 --- /dev/null +++ b/assignments/code.js @@ -0,0 +1,41 @@ +function Parent(attributes) { + this.gender = attributes.gender; + this.age = attributes.age; + this.name = attributes.name; + this.homeTown = attributes.homeTown +} + +function Child(attributes) { + Parent.call(this, attributes); // binding to Parent + this.isChild = attributes.isChild; // a special attribute to Child + +} + +Parent.prototype.yabbaDabba = function () { + return 'Yabba dabba doo!'; +}; + +Parent.prototype.speak = function () { + return `Hello, my name is ${this.name}`; +}; + +Child.prototype = Object.create(Parent.prototype); +Child.prototype.checkIfChild = function () { + return `My name is ${this.name}.`;// \nAm I a Child? ${pebbles instanceof Child}.\nAm I a Parent? ${pebbles instanceof Parent}.`; +}; + + + + + +const fred = new Parent({ gender: 'Male', age: 35, name: 'Fred', homeTown: 'Bedrock' }); + +const wilma = new Parent({ gender: 'Female', age: 37, name: 'Wilma', homeTown: 'Bedrock' }); + +const pebbles = new Child({ gender: 'Female', age: 3, name: 'Pebbles', homeTown: 'Bedrock', isChild: true }); + +console.log("***** Child *****"); +console.log("5.", pebbles); +console.log("6.", pebbles.speak()); +console.log("7.", pebbles.checkIfChild()); +console.log("8.", pebbles.yabbaDabba()); \ No newline at end of file diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..668073a87 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,121 @@ // CODE here for your Lambda Classes + +class Person { + constructor(personAttributes) { + this.name = personAttributes.name, + this.age = personAttributes.age, + this.location = personAttributes.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, + this.gradingScale = attributes.gradingScale + } + demo() { + return (`Today we are learning about ${this.specialty}`) + } + grade() { + return (`${this.name} receives a perfect score on ${this.specialty}`); + } + +} + + +class Students extends Person { + constructor(studentAttributes) { + super(studentAttributes); + this.previousBackground = studentAttributes.previousBackground, + this.classname = studentAttributes.classname, + this.favSubjects = studentAttributes.favSubjects + this.gradingScale = studentAttributes.gradingScale + } + listsSubjects() { + return ['HTML', 'CSS', 'JavaScript'] + } + prassignment() { + return (`${this.name} has submitted a PR for ${this.specialty}`) + } + sprintChallenge() { + return (`${this.name} has begun sprint challenge on ${this.specialty} `); + } + score() { + if (this.gradingScale >= 70) { + return `Congratulations, you have graduated!`; + } + return `Still grading to determine if passing.`; + } +} + +class Projectmanagers extends Instructor { + constructor(pmAttributes) { + super(pmAttributes); + this.gradClassName = pmAttributes.gradClassName, + this.favInstructor = pmAttributes.favInstructor, + this.channel = pmAttributes.channel + } + standUp() { + return (`${this.name} announces to ${this.channel}, @channel standby times!`) + } + debugsCode() { + return (`${this.name} debugs ${this.name}'s code on ${this.specialty}`) + } +} + +const user = new Person({ + name: 'Fred', + age: 45, + location: 'Bedrock', + catchPhrase: `it is what it is` + +}); + +const student = new Students({ + name: 'Jane', + location: 'Tampa', + age: 25, + favLanguage: 'JavaScript', + specialty: 'CSS', + previousBackground: 'teacher', + classname: 'Web24', + favSubjects: ['HTML', 'CSS', 'JavaScript'], + gradingScale: Math.floor(Math.random() * 100) + 1 +}); + +const instruct = new Instructor({ + name: 'Tina', + location: 'Utah', + age: 34, + favLanguage: 'HTML', + specialty: 'React', + catchPhrase: `Don't forget the homies` +}); + +const projectMag = new Projectmanagers({ + name: 'Tom', + location: 'San Francisco', + age: 34, + favLanguage: 'JavaScript', + specialty: 'Front-end', + catchPhrase: `Don't forget the homies`, + channel: 'Web24' +}); + +console.log(user.speak()); +console.log(instruct.demo()); +console.log(instruct.grade()); +console.log(student.listsSubjects()); +console.log(student.prassignment()); +console.log(student.sprintChallenge()); +console.log(projectMag.standUp()); +console.log(projectMag.debugsCode()); +console.log(student.gradingScale); +console.log(student.score()); diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..9ba87c1b8 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,99 @@ 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(gameAttributes) { + this.createdAt = gameAttributes.createdAt, + this.name = gameAttributes.name, + this.dimensions = gameAttributes.dimensions + } + destroy() { + return (`${this.name} was removed from the game`); + } +} + +class CharacterStats extends GameObject { + constructor(characterAttributes) { + super(characterAttributes); + this.healthPoints = characterAttributes.healthPoints + } + takeDamage() { + return (`${this.name} took damage.`); + } +} +class Humanoid extends CharacterStats { + constructor(humanoidAttributes) { + super(humanoidAttributes); + this.team = humanoidAttributes.team, + this.weapons = humanoidAttributes.weapons, + this.language = humanoidAttributes.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. +