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 problem = this.problems.find(x => x.id === id);
- if (!problem) {
- problem = {
- id,
- difficulty: Number(difficulty)
- }
- this.problems.push(problem);
- }
- return this.problems;
- }
- getProblems() {
- return this.problems;
- }
- showProblemSolution(id) {
- let problem = this.problems.find(x => x.id === id);
- if (!problem) {
- throw new Error(`Problem with id ${id} not found.`);
- } else {
- problem.difficulty--;
- return problem;
- }
- }
- }
- class Student extends Person{
- constructor( firstName, lastName, graduationCredits, problems ){
- super(firstName,lastName);
- this.graduationCredits = Number(graduationCredits);
- this.myCredits = 0;
- this.solvedProblems = [];
- this.problems = problems;
- }
- solveProblem(id){
- let problem = this.problems.find(x => x.id === id);
- if(!problem){
- throw new Error(`Problem with id ${ id } not found.`);
- } else{
- if(!this.solvedProblems.includes(problem)){
- this.myCredits += problem.difficulty;
- this.solvedProblems.push(problem);
- }
- }
- return this.myCredits;
- }
- graduate(){
- if(this.myCredits >= this.graduationCredits){
- return `${this.firstName} ${this.lastName} has graduated succesfully.`;
- } else{
- let neededCredits = this.graduationCredits - this.myCredits;
- return `${this.firstName} ${this.lastName}, you need ${ neededCredits } credits to graduate.`;
- }
- }
- }
- return {
- Person,
- Teacher,
- Student
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement