-
Notifications
You must be signed in to change notification settings - Fork 0
Jasyn Marais - JavaScript IV #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
78f92a3
cc4c93d
f793d97
bc21a05
ff4b48a
aa6803f
7117d5a
bfef556
1b8f2a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,177 @@ | ||
| console.log('****Lambda-classes:****'); | ||
|
|
||
| // CODE here for your Lambda Classes | ||
| /* | ||
| #### Person | ||
| * First we need a Person class. This will be our `base-class` | ||
| * Person receives `name` `age` `location` all as props | ||
| * Person receives `speak` as a method. | ||
| * This method logs out a phrase `Hello my name is Fred, I am from Bedrock` where `name` and `location` are the object's own props | ||
| */ | ||
| class Person { | ||
| constructor(data) { | ||
| this.name = data.name; | ||
| this.age = data.age; | ||
| this.location = data.location; | ||
| } | ||
| speak() { | ||
| console.log(`Hello my name is ${this.name}, I am from ${this.location}`); | ||
| return `Hello my name is ${this.name}, I am from ${this.location}`; | ||
| } | ||
| } | ||
| /* | ||
| #### Instructor | ||
| * Now that we have a Person as our base class, we'll build our Instructor class. | ||
| * Instructor uses the same attributes that have been set up by Person | ||
| * Instructor has the following unique props: | ||
| * `specialty` what the Instructor is good at i.e. 'redux' | ||
| * `favLanguage` i.e. 'JavaScript, Python, Elm etc.' | ||
| * `catchPhrase` i.e. `Don't forget the homies` | ||
| * Instructor has the following methods: | ||
| * `demo` receives a `subject` string as an argument and logs out the phrase 'Today we are learning about {subject}' where subject is the param passed in. | ||
| * `grade` receives a `student` object and a `subject` string as arguments and logs out '{student.name} receives a perfect score on {subject}' | ||
| */ | ||
| class Instructor extends Person { | ||
| constructor(data) { | ||
| super(data); | ||
| this.specialty = data.specialty; | ||
| this.favLanguage = data.favLanguage; | ||
| this.catchPhrase = data.catchPhrase; | ||
| } | ||
| demo(subject) { | ||
| console.log(`Today we are learning about ${subject}`); | ||
| return `Today we are learning about ${subject}`; | ||
| } | ||
| grade(student, subject) { | ||
| console.log(`${student.name} receives a perfect score on ${subject}`); | ||
| return `${student.name} receives a perfect score on ${subject}`; | ||
| } | ||
| randGrade(student) { // stretch | ||
| student.grade = Number(student.grade); | ||
| if(student.grade >= 70) { | ||
| console.log(`${student.name} just graduated!`); | ||
| return `${student.name} just graduated!`; | ||
| } | ||
| student.grade = Number(student.grade) + Number(((Math.random() * 10) - 5).toFixed(0)); | ||
| console.log(`${student.name} has a ${student.grade}% grade`); | ||
| return `${student.name} has a ${student.grade}% grade`; | ||
| } | ||
| } | ||
| let grant = new Instructor({ | ||
| name: 'Grant', location: 'ZA', age: 38, | ||
| favLanguage: 'JavaScript', specialty: 'Front-end', catchPhrase: `Don't forget the homies` | ||
| }); | ||
| let shaz = new Instructor({ | ||
| name: 'Shaz', location: 'US', age: 36, | ||
| favLanguage: 'CSS', specialty: 'Front-end', catchPhrase: `One time shoe shine` | ||
| }); | ||
| let arianna = new Instructor({ | ||
| name: 'Arianna', location: 'UK', age: 29, | ||
| favLanguage: 'JavaScript', specialty: 'Back-end', catchPhrase: `Master is Sacred` | ||
| }); | ||
| /* | ||
| #### Student | ||
| * Now we need some students! | ||
| * Student uses the same attributes that have been set up by Person | ||
| * Student has the following unique props: | ||
| * `previousBackground` i.e. what the Student used to do before Lambda School | ||
| * `className` i.e. CS132 | ||
| * `favSubjects`. i.e. an array of the student's favorite subjects ['Html', 'CSS', 'JavaScript'] | ||
| * Student has the following methods: | ||
| * `listsSubjects` a method that logs out all of the student's favoriteSubjects one by one. | ||
| * `PRAssignment` a method that receives a subject as an argument and logs out that the `student.name has submitted a PR for {subject}` | ||
| * `sprintChallenge` similar to PRAssignment but logs out `student.name has begun sprint challenge on {subject}` | ||
| */ | ||
| class Student extends Person { | ||
| constructor(data) { | ||
| super(data); | ||
| this.className = data.className; | ||
| this.favSubjects = data.favSubjects; | ||
| this.previousBackground = data.previousBackground; | ||
|
|
||
| this.grade = (Math.random() * 100).toFixed(0); // stretch | ||
| } | ||
| listSubjects() { | ||
| console.log(`${this.name} favourite subjects: ${this.favSubjects}`); | ||
| return `${this.name} favourite subjects: ${this.favSubjects}`; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| PRAssignment(subject) { | ||
| console.log(`${this.name} has submitted a PR for ${subject}`); | ||
| return `${this.name} has submitted a PR for ${subject}`; | ||
| } | ||
| sprintChallenge(subject) { | ||
| console.log(`${this.name} has begun sprint challenge on ${subject}`); | ||
| return `${this.name} has begun sprint challenge on ${subject}`; | ||
| } | ||
| } | ||
| let byron = new Student({ | ||
| name: 'Byron', location: 'ZA', age: 37, | ||
| className: 'JS-I', | ||
| favSubjects: ['HTML', 'CSS', 'Javascript'], | ||
| previousBackground: `Advertising` | ||
| }); | ||
| let sam = new Student({ | ||
| name: 'Sam', location: 'UK', age: 36, | ||
| className: 'JS-II', | ||
| favSubjects: ['HTML', 'CSS', 'Javascript'], | ||
| previousBackground: `Film Editor` | ||
| }); | ||
| let mojo = new Student({ | ||
| name: 'Mojo', location: 'US', age: 29, | ||
| className: 'JS-III', | ||
| favSubjects: ['HTML', 'CSS', 'Javascript'], | ||
| previousBackground: `Rat Catcher` | ||
| }); | ||
| /* | ||
| #### Project Manager | ||
| * Now that we have instructors and students, we'd be nowhere without our PM's | ||
| * ProjectManagers are extensions of Instructors | ||
| * ProjectManagers have the following unique props: | ||
| * `gradClassName`: i.e. CS1 | ||
| * `favInstructor`: i.e. Sean | ||
| * ProjectManagers have the following Methods: | ||
| * `standUp` a method that takes in a slack channel and logs `{name} announces to {channel}, @channel standy times! | ||
| * `debugsCode` a method that takes in a student object and a subject and logs out `{name} debugs {student.name}'s code on {subject}` | ||
| */ | ||
| class ProjectManager extends Instructor { | ||
| constructor(data) { | ||
| super(data); | ||
| this.gradClassName = data.gradClassName; | ||
| this.favInstructor = data.favInstructor; | ||
| } | ||
| standUp(channel) { | ||
| console.log(`${this.name} announces to ${channel}, @channel standy times!`); | ||
| return `${this.name} favourite subjects: ${this.favSubjects}`; | ||
| } | ||
| debugsCode(student, subject) { | ||
| console.log(`${this.name} debugs ${student.name}'s code on ${subject}`); | ||
| return `${this.name} debugs ${student.name}'s code on ${subject}`; | ||
| } | ||
| } | ||
| let jasyn = new ProjectManager({ | ||
| name: 'Jasyn', location: 'ZA', age: 38, | ||
| gradClassName: 'JS-I', | ||
| favInstructor: 'Gabriel', | ||
| }); | ||
| let lolo = new ProjectManager({ | ||
| name: 'Lolo', location: 'UK', age: 37, | ||
| gradClassName: 'JS-II', | ||
| favInstructor: 'Gabriel', | ||
| }); | ||
| let babou = new ProjectManager({ | ||
| name: 'Babou', location: 'US', age: 27, | ||
| gradClassName: 'JS-III', | ||
| favInstructor: 'Gabriel', | ||
| }); | ||
|
|
||
| grant.demo('Javascript Fundamentals'); | ||
| shaz.grade(sam, 'Javascript Fundamentals'); | ||
| arianna.randGrade(mojo); | ||
|
|
||
| byron.listSubjects(); | ||
| sam.PRAssignment('Javascript Fundamentals'); | ||
| mojo.sprintChallenge('Javascript Fundamentals'); | ||
|
|
||
| jasyn.standUp('#webeu4'); | ||
| lolo.debugsCode(byron, 'Javascript Fundamentals'); | ||
| babou.debugsCode(sam, 'Javascript Fundamentals'); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| console.log('****Prototype-refactor:****'); | ||
|
|
||
| /* | ||
|
|
||
| Prototype Refactor | ||
|
|
@@ -7,3 +9,74 @@ 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. | ||
|
|
||
| */ | ||
|
|
||
| /* TASK 1 */ | ||
|
|
||
| class Person3 { | ||
| constructor(name, age) { | ||
| this.name = name; | ||
| this.age = age; | ||
| this.stomach = []; | ||
| } | ||
| greet() { | ||
| return `My name is ${this.name} and I'm ${this.age} years old.`; | ||
| } | ||
| eat(food) { | ||
| this.stomach.push(food); | ||
| return `${this.name} just ate ${food}.`; | ||
| } | ||
| poop() { | ||
| this.stomach = []; | ||
| return `I pooped and now my stomach is empty.`; | ||
| } | ||
| } | ||
|
|
||
| let me = new Person3('Billy Bob', 18); | ||
|
|
||
| console.log(me.greet(), me.eat('KFC'), me.poop()); | ||
|
|
||
| /* TASK 2 */ | ||
|
|
||
| class Car { | ||
| constructor(model, make) { | ||
| this.model = model; | ||
| this.make = make; | ||
| this.odometer = 0; | ||
| this.canDrive = true; | ||
| } | ||
| drive(distance) { | ||
| if (this.canDrive) { | ||
| this.odometer += Number(distance); | ||
| return `Drove ${distance} miles. Odometer: ${this.odometer}.`; | ||
| } | ||
| return `I crashed at ${this.odometer} miles!`; | ||
| } | ||
|
Comment on lines
+47
to
+53
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not conform with the instruction/spec |
||
| crash() { | ||
| this.canDrive = false; | ||
| return `I just crashed.`; | ||
| } | ||
| repair() { | ||
| this.canDrive = true; | ||
| return `I've been repaired.`; | ||
| } | ||
| } | ||
|
|
||
| let car = new Car('2006', 'Opel'); | ||
|
|
||
| console.log(car.drive(25), car.crash(), car.repair()); | ||
|
|
||
| /* TASK 3 */ | ||
|
|
||
| class Baby extends Person3 { | ||
| constructor(name, age) { | ||
| super(name, age); | ||
| } | ||
| play() { | ||
| return `Baby played and said "Goo-goo ga-ga".`; | ||
| } | ||
| } | ||
|
|
||
| let baby = new Baby('Arianna', 0.5); | ||
|
|
||
| console.log(baby.greet(), baby.play()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need mutating the object, you could create a new variable off of the student object, e.g
let studentGrade = Number(student.grade)