From 14dc27386ee6c492fbd5a63a91e89948773c6294 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 24 May 2018 17:54:13 -0400 Subject: [PATCH] david layman javascipt-IV --- assignments/lambda-classes.js | 88 +++++++++++++++++++++++++++++++ assignments/prototype-refactor.js | 39 +++++++------- 2 files changed, 107 insertions(+), 20 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..d88d66784 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,89 @@ // CODE here for your Lambda Classes +class people{ +constructor(params){ + this.age=params.age; + this.name=params.name; + this.location=params.location; + this.gender=params.gender; + } +speak(){ + return ("Hello, my name is "+this.name+", and I'm from "+this.location); + } +} +class instructor extends people{ +constructor(params){ + super(params); + this.specialty=params.specialty; + this.favLang=params.favLang; + this.chatchPhrase=params.catchPhrase; + } + demo(subject){ + return("Yo, yo, yo, today we're learning about "+subject+" ya'll!") + } + grade(student,subject){ + return(student.name+" is a horrible dissapointment, and failed at "+subject) + } +} +class student extends people{ +constructor(params){ + super(params); + this.previousBackground=params.previousBackground; + this.className=params.className; + this.favSubjects=params.favSubjects; + } + listSubjects(){ + function myFunc(value){ + console.log(value); + } + this.favSubjects.forEach(myFunc); + } +} +class projectManager extends instructor{ +constructor(params){ + super(params); + this.gradClassName=params.gradClassName; + this.favInstructor=params.favInstructor; + } + standUp(chan){ + console.log(`${this.name} announces to ${chan}, @channel standy times!`) + } + debugsCode(student,subject){ + console.log(this.name+" laughs at "+student.name+" for screwing up at "+subject) + } +} + +const fred = new instructor({ + "gender": "M", + "age": 35, + "name": "Fred", + "location": "bedrock", + "specialty": "Rock.os", + "favLang": "club++", + "catchPhrase": "Yabba Dabba Doo!", +}); +const David = new student({ + "gender": "M", + "age": 21, + "name": "David", + "location": "OH", + "previousBackground": "highschool student", + "className": "cs11", + "favSubjects": ['math','coding','history','tigers'], +}); +const Josh = new projectManager({ + "gender": "M", + "age": '30-ish', + "name": "Josh", + "location": "the moon", + "specialty": "everything", + "favLang": "English", + "catchPhrase": "Yabba Dabba Doo!", + "gradClassName": "cs4", + "favInstructor": "himself", +}); + + +console.log(fred.speak()); +console.log(fred.grade(David, 'science')); +David.listSubjects(); +Josh.standUp('our channel'); \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index e55ae39c0..9450f81b4 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -2,39 +2,38 @@ // Today 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. -function GameObject(options) { +class GameObject { +constructor(options){ this.createdAt = options.createdAt; this.dimensions = options.dimensions; -} - -GameObject.prototype.destroy = function() { + }; +destroy() { return `Object was removed from the game.`; }; +} -function CharacterStats(characterStatsOptions) { - GameObject.call(this, characterStatsOptions); +class CharacterStats extends GameObject { + constructor(characterStatsOptions){ + super(characterStatsOptions); this.hp = characterStatsOptions.hp; this.name = characterStatsOptions.name; -} - -CharacterStats.prototype = Object.create(GameObject.prototype); - -CharacterStats.prototype.takeDamage = function() { + }; + takeDamage() { return `${this.name} took damage.`; -}; + }; +} -function Humanoid(humanoidOptions) { - CharacterStats.call(this, humanoidOptions); +class Humanoid extends CharacterStats { + constructor(humanoidOptions){ + super(humanoidOptions); this.faction = humanoidOptions.faction; this.weapons = humanoidOptions.weapons; this.language = humanoidOptions.language; -} - -Humanoid.prototype = Object.create(CharacterStats.prototype); - -Humanoid.prototype.greet = function() { + }; + greet() { return `${this.name} offers a greeting in ${this.language}.`; -}; + }; +} const mage = new Humanoid({ createdAt: new Date(),