Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
56ddbec
initial commit
losephjambert Aug 22, 2019
3b55e6e
updates readme
losephjambert Aug 22, 2019
c214556
adds game code from JS-III assignment
losephjambert Aug 22, 2019
9ac1823
removes redundant tests for GameObject and CharacterStats
losephjambert Aug 22, 2019
e842df1
refactors GamoeObject to class syntax
losephjambert Aug 22, 2019
c5e5c7f
refactors CharacterStats to use class syntax
losephjambert Aug 22, 2019
69608d0
fixes syntax error and refactors Humanoid to use class syntax
losephjambert Aug 22, 2019
65f2793
refactors Villain and Hero to class syntax
losephjambert Aug 22, 2019
76e1e48
removes unnecessary comments and es5 constructor functions
losephjambert Aug 22, 2019
2063952
adds notes for reference while creating classes
losephjambert Aug 22, 2019
8b59fad
adds Person class
losephjambert Aug 22, 2019
5e18379
adds Instructor class
losephjambert Aug 22, 2019
d4624bd
adds Student class
losephjambert Aug 22, 2019
8d55895
stubs ProjectManager class
losephjambert Aug 22, 2019
c0214c4
fills in ProjectManager class
losephjambert Aug 22, 2019
e65abb8
removes destructuring from Student method listsSubjects
losephjambert Aug 22, 2019
1aeec69
adds test classes
losephjambert Aug 22, 2019
d767137
adds test cases for all class instances and all class methods
losephjambert Aug 22, 2019
c5e45eb
adds grade to Student class and updates all instances of Student to a…
losephjambert Aug 22, 2019
15f2cf7
adds all fields to instance of Instructor class
losephjambert Aug 22, 2019
bbc4de6
adds adjustGrade method to Instructor class
losephjambert Aug 22, 2019
691bd57
tests adjustGrade with Instructor and ProjectManager
losephjambert Aug 22, 2019
7e43766
adds test cases for Student graduate method
losephjambert Aug 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 60 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ This challenge focuses on classes in JavaScript using the new `class` keyword.

**Follow these steps to set up and work on your project:**

* [ ] Create a forked copy of this project.
* [ ] Add your project manager as collaborator on Github.
* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!).
* [ ] Create a new branch: git checkout -b `<firstName-lastName>`.
* [ ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [ ] Push commits: git push origin `<firstName-lastName>`.
- [x] Create a forked copy of this project.
- [x] Add your project manager as collaborator on Github.
- [x] Clone your OWN version of the repository (Not Lambda's by mistake!).
- [x] Create a new branch: git checkout -b `<firstName-lastName>`.
- [x] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
- [x] Push commits: git push origin `<firstName-lastName>`.

**Follow these steps for completing your project.**

* [ ] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
* [ ] Add your project manager as a reviewer on the pull-request
* [ ] Your project manager will count the project as complete by merging the branch back into master.
- [x] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
- [ ] Add your project manager as a reviewer on the pull-request
- [ ] Your project manager will count the project as complete by merging the branch back into master.

## Assignment Description

You already pretty much know all about classes but you're used to seeing them built in the following context:

```js
function Person(personAttributes) {
function Person(personAttributes) {
this.name = personAttributes.name;
this.age = personAttributes.age;
this.location = personAttributes.location;
Expand All @@ -33,28 +33,28 @@ function Person(personAttributes) {
const fred = new Person({
name: 'Fred',
age: 37,
location: 'Bedrock'
location: 'Bedrock',
});
```

* Because none of the above code is new, you're about to see your world get much much easier when dealing with Object Creation and Classical Inheritance as it pertains to JavaScript.
* The Class Keyword makes this SO MUCH EASIER!
* **Fork** and clone this repository.
* **Complete** all of the exercises found in the assignment files.
- Because none of the above code is new, you're about to see your world get much much easier when dealing with Object Creation and Classical Inheritance as it pertains to JavaScript.
- The Class Keyword makes this SO MUCH EASIER!
- **Fork** and clone this repository.
- **Complete** all of the exercises found in the assignment files.

## `prototype-refactor` - Take existing code and make it modern.

* You're going to work with your prototypes assignment you built out yesterday.
* `Challenge:` **Convert** all of your constructors into ES6 Classes using the `class` and `extends` keywords. You should be able to run your same logs and they should build out the proper expected behaviors.
- You're going to work with your prototypes assignment you built out yesterday.
- `Challenge:` **Convert** all of your constructors into ES6 Classes using the `class` and `extends` keywords. You should be able to run your same logs and they should build out the proper expected behaviors.

## `lambda-classes` - We need a roster of Lambda School personnel. Build it!

* We have a school to build here! This project will get you used to thinking about classes in JavaScript and building them from a brand new data set.
* Lambda personnel can be broken down into three different types of `people`.
* **Instructors** - extensions of Person
* **Students** - extensions of Person
* **Project Managers** - extensions of Instructors
* **IMPORTANT** - You'll need to create 2 - 3 objects for each class and test them according to their unique Attributes. For example:
- We have a school to build here! This project will get you used to thinking about classes in JavaScript and building them from a brand new data set.
- Lambda personnel can be broken down into three different types of `people`.
- **Instructors** - extensions of Person
- **Students** - extensions of Person
- **Project Managers** - extensions of Instructors
- **IMPORTANT** - You'll need to create 2 - 3 objects for each class and test them according to their unique Attributes. For example:

```js
const fred = new Instructor({
Expand All @@ -63,57 +63,57 @@ const fred = new Instructor({
age: 37,
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `Don't forget the homies`
catchPhrase: `Don't forget the homies`,
});
```

#### 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
- 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

#### 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}'
- 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}'

#### 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}`
- 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}`

#### 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}`
- 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}`

#### Stretch Problem

* Extend the functionality of the Student by adding a prop called grade and setting it equal to a number between 1-100.
* Now that our students have a grade build out a method on the Instructor (this will be used by _BOTH_ instructors and PM's) that will randomly add or subtract points to a student's grade. _Math.random_ will help.
* Add a graduate method to a student.
* This method, when called, will check the grade of the student and see if they're ready to graduate from Lambda School
* If the student's grade is above a 70% let them graduate! Otherwise go back to grading their assignments to increase their score.
- Extend the functionality of the Student by adding a prop called grade and setting it equal to a number between 1-100.
- Now that our students have a grade build out a method on the Instructor (this will be used by _BOTH_ instructors and PM's) that will randomly add or subtract points to a student's grade. _Math.random_ will help.
- Add a graduate method to a student.
- This method, when called, will check the grade of the student and see if they're ready to graduate from Lambda School
- If the student's grade is above a 70% let them graduate! Otherwise go back to grading their assignments to increase their score.
212 changes: 212 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,213 @@
// utilities
const getRandomNumber = (min, max) => Math.floor(Math.random() * (max - min) + min); // not inclusive of the max

// CODE here for your Lambda Classes

// ========== Person ========== // - base class
/*
- 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(attr) {
this.name = attr.name;
this.age = attr.age;
this.location = attr.location;
}
speak() {
return `Hello my name is ${this.name}, I am from ${this.location}.`;
}
}
// console.log(new Person({ name: 'joe', age: 32, location: 'Seattle' }).speak());

// ========== Instructor ========== // - inherits from Person
/*
- 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(attr) {
super(attr);
this.specialty = attr.specialty;
this.favLanguage = attr.favLanguage;
this.catchPhrase = attr.catchPhrase;
}

demo(subject) {
return `Today we are learning about ${subject}.`;
}

grade(student, subject) {
return `${student.name} receives a perfect score on ${subject}`;
}

adjustGrade(student, range = [1, 10]) {
const decrement = getRandomNumber(0, 2);
const score = getRandomNumber(range[0], range[1]);
decrement ? (student.grade -= score) : (student.grade += score);
if (student.grade > 100) student.grade = 100;
return `
${student.name}'s grade was ${decrement ? 'decremented' : 'incremented'} by ${score}.
${student.name}'s grade is now ${student.grade}.
${student.graduate()}
`;
}
}

// ========== Student ========== // - inherits from Person
/*
- 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(attr) {
super(attr);
this.previousBackground = attr.previousBackground;
this.className = attr.className;
this.favSubjects = attr.favSubjects;
this.grade = attr.grade;
}

listsSubjects() {
// this.favSubjects.forEach(subject => {
// console.log(subject);
// });
return `${this.name}'s favorite subjects are ${this.favSubjects.join(', ')}`;
}

PRAssignment(subject) {
return `${this.name} has submitted a PR for ${subject}`;
}

sprintChallenge(subject) {
return `${this.name} has begun a sprint challenge for ${subject}`;
}

graduate() {
return this.grade > 70 ? `Congratulations, ${this.name}! You've graduated from Lambda School!` : `Keep on practicing ${this.name}. You'll get there!`;
}
}

// ========== Project Manager ========== // - inherits from Instructor
/*
- 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(attr) {
super(attr);
this.gradClassName = attr.gradClassName;
this.favInstructor = attr.favInstructor;
}

standUp(channel) {
return `${this.name} announces to ${channel}, "@channel standy times!​​​​​"`;
}

debugsCode(student, subject) {
return `${this.name} debugs ${student.name}'s code on ${subject}`;
}
}

// ========== Tests ========== //

const webFoundationsInstructor = new Instructor({
name: 'Britt',
age: 32,
location: 'Toronto',
specialty: 'HTML && CSS',
favLanguage: 'JavaScript',
catchPhrase: 'In the thread, please',
});

const webStudent1 = new Student({
name: 'Joe',
age: 32,
location: 'Seattle',
previousBackground: 'Coffee',
className: 'WEB23',
favSubjects: ['JavaScript', 'CSS', 'React', 'Functional Programming'],
grade: 90,
});

const webStudent2 = new Student({
name: 'Stella',
age: 26,
location: 'Atlanta',
previousBackground: 'Musician',
className: 'WEB23',
favSubjects: ['Node', 'HTML', 'Vue', 'APIs'],
grade: 94,
});

const webPM1 = new ProjectManager({
name: 'Marc',
age: 38,
location: 'San Antonio',
gradClassName: 'WEB12',
favInstructor: 'Britt',
specialty: 'Functional Programming',
favLanguage: 'JavaScript',
catchPhrase: 'Oh, hi Marc!',
});

// webFoundationsInstructor
// webStudent1
// webStudent2
// webPM1

// test instances
console.log(webFoundationsInstructor);
console.log(webStudent1);
console.log(webStudent2);
console.log(webPM1);

// test methods
// - Instructor
console.log(webFoundationsInstructor.speak());
console.log(webFoundationsInstructor.demo('JavaScript'));
console.log(webFoundationsInstructor.grade(webStudent2, 'JavaScript'));
console.log(webFoundationsInstructor.adjustGrade(webStudent2, [4, 20]));

// - Student
console.log(webStudent1.speak());
console.log(webStudent1.listsSubjects());
console.log(webStudent1.PRAssignment('JavaScript-IV'));
console.log(webStudent1.sprintChallenge('JavaScript'));

console.log(webStudent2.speak());
console.log(webStudent2.listsSubjects());
console.log(webStudent2.PRAssignment('JavaScript-IV'));
console.log(webStudent2.sprintChallenge('JavaScript'));

// - Project Manager
console.log(webPM1.speak());
console.log(webPM1.demo('React'));
console.log(webPM1.grade(webStudent1, 'React'));
console.log(webPM1.standUp('#web23_marc'));
console.log(webPM1.debugsCode(webStudent1, 'flexbox'));
console.log(webPM1.adjustGrade(webStudent1, [5, 20]));
Loading