Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ 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.**

Expand Down
130 changes: 130 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,131 @@
console.log("———");

// CODE here for your Lambda Classes
class PersonAlt { // Had to add 'Alt' so wouldn't clash with Person in the other file!
constructor(name, age, location) {
this.name = name;
this.age = age;
this.location = location;
}

speak() {
return `Hello my name is ${this.name}, I am from ${this.location}.`
}
}

const fred = new PersonAlt('Fred', 37, 'Bedrock');
console.log(fred.speak());
// Working as expected!

class Instructor extends PersonAlt {
constructor(name, age, location, specialty, favLanguage, catchPhrase) {
super(name, age, location);
this.specialty = specialty;
this.favLanguage = favLanguage;
this.catchPhrase=catchPhrase;
}

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

grade(studentObject, subject) {
console.log(`${studentObject.name} receives a perfect score on ${subject}.`);
}

changeGrade(studentObject) { // Stretch
let randomChange;
if (Math.random() > 0.5) {
randomChange = Math.round(Math.random() * 100);
} else {
randomChange = -Math.round(Math.random() * 100);
}

if (studentObject.grade + randomChange <= 0) {
studentObject.grade = 0;
} else if (studentObject.grade + randomChange >= 100) {
studentObject.grade = 100;
} else {
studentObject.grade += randomChange;
}
}
}

const david = new Instructor("David", 66, "Oxford", "Quantum Computers", "Java", "Problems are soluble!");
david.demo("Bad Philosophy");
david.grade(fred, "Good Explanations");
console.log(david.speak());

class Student extends PersonAlt {
constructor(name, age, location, previousBackground, className, favSubjects) {
super(name, age, location);
this.previousBackground = previousBackground;
this.className = className;
this.favSubjects = favSubjects;
this.grade = Math.round(Math.random() * 100); // Stretch
}

listSubjects() { // I prefer 'listSubjects' to 'listsSubjets'...
this.favSubjects.forEach(subject => console.log(subject));
}

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

sprintChallenge(subject) {
console.log(`${this.name} has begun sprint challenge on ${subject}`);
}

graduate() { // Stretch
if (this.grade > 70) {
console.log(`${this.name} has graduated with a grade of ${this.grade}/100!`);
} else {
console.log(`${this.name} didn't pass with a grade of ${this.grade}/100.`);
Instructor.prototype.changeGrade(this);
console.log(`${this.name} took the exam again. New grade: ${this.grade}/100`);
this.graduate(); // A little bit of recursion, why not? :P
}
}
}

const carnun = new Student("Carnun", 22, "London", "Philosophy", "WebEU3", ["Epistemology", "Philosophy of Science", "Philosophy of Mind"]);
carnun.listSubjects();
carnun.PRAssignment("Artificial Creativity");
carnun.sprintChallenge("Getting to Writing, Finally");
console.log(carnun.speak());

class ProjectManager extends Instructor {
constructor(name, age, location, specialty, favLanguage, catchPhrase, gradClassName, favInstructor) {
super(name, age, location, specialty, favLanguage, catchPhrase);
this.gradClassName = gradClassName;
this.favInstructor = favInstructor;
}

standUp(slackChannel) {
console.log(`${this.name} announces to ${slackChannel}, @channel standy times!`);
}

debugCode(studentObject, subject) {
console.log(`${this.name} debugs ${studentObject.name}'s code on ${subject}`);
}
}

const popper = new ProjectManager("Popper", 116, "The LSE", "Philosophy of Science", "javaScript", "I am not a beleif philosopher", "WebEU1", "david");
popper.standUp("#webEU3");
popper.debugCode(fred, "Classes and Inheritance");
popper.demo("Evolutionary Epistemology");
console.log(popper.speak());

// Stretch:
for (let i = 0; i < 3; i++) { // Testing Instructor.prototype.changeGrade(studentObject)
console.log(`Carnun's grade before David changes it: ${carnun.grade}.`);
david.changeGrade(carnun);
console.log(`Carnun's grade after David changes it, and before Popper changes it: ${carnun.grade}.`);
popper.changeGrade(carnun);
console.log(`Carnun's grade after Popper changes it: ${carnun.grade}.`)
}

console.log("...")
carnun.grade = 60; // Testing Student.prototype.graduate()
carnun.graduate();
Loading