Created
March 24, 2022 03:27
-
-
Save cacheflow/af013a40284de0c5512b19b6ef232463 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student { | |
constructor(name, email) { | |
this.name = name; | |
this.email = email; | |
} | |
} | |
class Bootcamp { | |
constructor(name, level, students = []) { | |
this.name = name; | |
this.level = level | |
this.students = students; | |
} | |
logStudents(){ | |
console.log(this.students); | |
} | |
registerStudent(studentToRegister) { | |
if (studentToRegister == undefined){ | |
console.log("Invalid Name or Email"); | |
return false; | |
} | |
if (!studentToRegister.name || !studentToRegister.email) { | |
console.log("Invalid Name or Email"); | |
return false; | |
} | |
const foundStudent = this.students.find((currentStudent) => { | |
return currentStudent.email === studentToRegister.email; | |
}) | |
if (foundStudent == undefined) { | |
this.students.push(studentToRegister); | |
console.log(`Success ${studentToRegister.name} has registered to ${this.name}`); | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
} | |
testStudent = new Student('Bugs Bunny', '[email protected]'); | |
console.log(testStudent); | |
if ( testStudent.name === 'Bugs Bunny' && testStudent.email === '[email protected]') { | |
console.log('TASK 1: PASS'); | |
} | |
reactBootcamp = new Bootcamp("React", "Advanced"); | |
console.log(reactBootcamp); | |
if ( reactBootcamp.name === 'React' && reactBootcamp.level === 'Advanced' | |
&& Array.isArray(reactBootcamp.students) && reactBootcamp.students.length === 0) { | |
console.log('TASK 2: PASS'); | |
} | |
const runTest = (bootcamp, student) => { | |
const attemptOne = bootcamp.registerStudent(student); | |
const attemptTwo = bootcamp.registerStudent(student); | |
const attemptThree = bootcamp.registerStudent(new Student("Babs Bunny")); | |
console.log(bootcamp.logStudents()) | |
if ( attemptOne && !attemptTwo && !attemptThree) { | |
console.log("TASK 3: PASS"); | |
} | |
}; | |
runTest(reactBootcamp, testStudent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment