Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solveClasses() {
- class Person {
- constructor(firstName, lastName) {
- this.firstName = firstName;
- this.lastName = lastName;
- this.problems = [];
- }
- toString() {
- return `${this.firstName} ${this.lastName} is part of SoftUni community now!`
- }
- }
- class Teacher extends Person {
- constructor(firstName, lastName) {
- super(firstName, lastName);
- }
- createProblem(id, difficulty) {
- let newProblem = {
- id,
- difficulty
- }
- this.problems.push(newProblem);
- return this.problems;
- }
- getProblem() {
- return this.problems;
- }
- showProblemSolution(id) {
- let check = this.problems.find(p => p.id === id);
- if (!check) {
- throw new Error(`Problem with id ${id} not found.`)
- } else {
- check.difficulty -= 1;
- return check;
- }
- }
- }
- class Student extends Person {
- constructor(firstName, lastName, graduationCredits, problems) {
- super(firstName, lastName);
- this.graduationCredits = graduationCredits;
- this.myCredits = 0;
- this.solvedProblems = [];
- this.problems=problems;
- }
- solveProblem(id) {
- let check = this.problems.find(p => p.id === id);
- if (!check) {
- throw new Error(`Problem with id ${id} not found.`)
- } else if (!this.solvedProblems.includes(check)) {
- this.solvedProblems.push(check);
- this.myCredits += check.difficulty;
- }
- return this.myCredits;
- }
- graduate() {
- if (this.myCredits >= this.graduationCredits) {
- return `${this.firstName} ${this.lastName} has graduated succesfully.`
- } else {
- return `${this.firstName} ${this.lastName}, you need ${this.graduationCredits - this.myCredits} credits to graduate.`
- }
- }
- }
- return {
- Person,
- Teacher,
- Student
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement