From 2ba969ee63fda0aef6f49b140cc666a381874572 Mon Sep 17 00:00:00 2001 From: -tristan- Date: Thu, 24 May 2018 15:57:35 -0700 Subject: [PATCH 1/2] prototype-refactor.js --- assignments/prototype-refactor.js | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index e55ae39c0..2a322e875 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -2,6 +2,7 @@ // 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. +/*//PROTOTYPE INHERITANCE - COMMITED OUT function GameObject(options) { this.createdAt = options.createdAt; this.dimensions = options.dimensions; @@ -10,7 +11,20 @@ function GameObject(options) { GameObject.prototype.destroy = function() { return `Object was removed from the game.`; }; +*/ +//CLASS CONTRUCTOR ES6 +//BASE (PARENT) CLASS +class GameObject { + constructor (parentParams) { + this.createdAt = parentParams.createdAt ; + this.dimensions = parentParams.dimensions ; + } + destroy() { + return `${this.name} was removed from the game!` ; + } +} +/* function CharacterStats(characterStatsOptions) { GameObject.call(this, characterStatsOptions); this.hp = characterStatsOptions.hp; @@ -22,7 +36,24 @@ CharacterStats.prototype = Object.create(GameObject.prototype); CharacterStats.prototype.takeDamage = function() { return `${this.name} took damage.`; }; +*/ + +//CHILD CLASS BELOW +////'EXTENDS' (creates a child) +//NOTE SYNTAX: class child EXTENDS parent +class CharacterStats extends GameObject { + constructor (childParams) { +//'SUPER' KEYWORD IS USED TO ACCESS AND CALL FUNCTIONS ON AN OBJECTS PARENT​​​​​ + super(childParams) ; + this.hp = childParams.hp ; + this.name = childParams.name + } + takeDamage() { + return `${this.name} took damage.` ; + } +} +/* function Humanoid(humanoidOptions) { CharacterStats.call(this, humanoidOptions); this.faction = humanoidOptions.faction; @@ -35,6 +66,20 @@ Humanoid.prototype = Object.create(CharacterStats.prototype); Humanoid.prototype.greet = function() { return `${this.name} offers a greeting in ${this.language}.`; }; +*/ +class Humanoid extends CharacterStats { + constructor (grandChildParams) { + super(grandChildParams) ; + this.faction = grandChildParams.faction ; + this.weapons = grandChildParams.weapons ; + this.language = grandChildParams.language ; + } + greet() { + return `${this.name} offers a greeting in ${this.language}.` ; + } +} + +////END OF MY CODE const mage = new Humanoid({ createdAt: new Date(), From b70224bd23034514074c97fea14f1ead83765ab7 Mon Sep 17 00:00:00 2001 From: -tristan- Date: Mon, 28 May 2018 23:28:49 -0700 Subject: [PATCH 2/2] completed lambda-classes.js --- assignments/lambda-classes.js | 122 ++++++++++++++++++++++++++++++ assignments/prototype-refactor.js | 2 +- 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..2873d82d1 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,123 @@ // CODE here for your Lambda Classes +class Person { + constructor (personParams) { + this.name = personParams.name ; + this.age = personParams.age ; + this.location = personParams.location ; + this.gender = personParams.gender ; + } + speak(){ + console.log(`Hello my name is ${this.name}, I am from ${this.location}.`) ; + } +} + +class Instructor extends Person { + constructor (instructorParams) { + super(instructorParams) ; + this.specialty = instructorParams.specialty ; + this.favLanguage = instructorParams.favLanguage ; + this.catchPhrase = instructorParams.catchPhrase ; + } + demo(subject){ + console.log (`Today we are learning about ${subject}!`) ; + } + grade(student, subject){ + console.log (`${student.name} receives a perfect score on ${subject}.`) ; + } + /* strech */ + applyGrade(student){ + let newGrade = student.grade ; + let randomGrade = Math.floor(Math.random()*100) ; + let negOrPosNum = Math.random() < 0.5 ? -1 : 1 ; + newGrade = newGrade + (randomGrade * negOrPosNum) ; + if (newGrade >= 100){ + return student.grade = 100 ; + }else if(newGrade < 0){ + return student.grade = 0 ; + }else{ + return student.grade = newGrade ; + } + } +} + +class Student extends Person { + constructor (studentParams) { + super(studentParams) ; + this.previousBackground = studentParams.previousBackground ; + this.className = studentParams.className ; + this.favSubjects = studentParams.favSubjects ; + /* strech */ + this.grade = studentParams.grade; + } + + listsSubjects(){ + + let newArr = []; + + for(let i=0; i < this.favSubjects.length; i++){ + newArr.push(this.favSubjects[i]) ; + } + console.log(`${this.name}s favourite subjects are ${newArr}`) ; + + return newArr ; + } + + PRAssignment(subject) + { + console.log((`${this.name} has submitted a PR for ${subject}!`)) ; + } + sprintChallenge(subject){ + console.log(`${this.name} has begun sprint challenge on ${subject}`); + } + /* strech */ + graduate(student){ + if (this.grade > 70){ + console.log(`${this.name} is cleared for takeoff!`) ; + }else { + console.log(`Back to the drawing board!`) ; + } + } +} + +class PM extends Instructor { + constructor(pmParams){ + super(pmParams) ; + this.gradClassName = pmParams.gradClassName ; + this.gradClassName = pmParams.favInstructor ; + } + standUp(slackChannel){ + console.log(`${this.name} announces to ${slackChannel}, @channel standy times!​​​​​`) ; + } + debugsCode(student, subject){ + console.log(`${this.name} debugs ${student.name}'s code on ${subject}`) ; + } +} +const tristan = new Student({ + //props from parent + name: 'Tristan', + age: 34, + gender: true, + //props from child + favSubjects: ['html', 'css', 'js'] +}); +const haywood = new PM({ + name: 'Haywood' +}); +const josh = new Instructor ({ + catchPhrase: 'deep dive' +}) +tristan.listsSubjects();//? +const randomValueInArray = function (array) { + return array[Math.floor(Math.random()*array.length)] ;//? +} +tristan.PRAssignment(randomValueInArray(tristan.favSubjects))//*? +tristan.sprintChallenge('excellence');//*? +haywood.debugsCode(tristan,'javaScript'); //*? +josh.demo(josh.catchPhrase);//*? + +/* strech */ +tristan.grade = 85; +console.log(josh.applyGrade(tristan));//*? +tristan//? +tristan.graduate();//*? + diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 2a322e875..2019c2c8a 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -21,7 +21,7 @@ class GameObject { this.dimensions = parentParams.dimensions ; } destroy() { - return `${this.name} was removed from the game!` ; + return `${this.name} was removed from the game!` ;//? } } /*