Skip to content

Instantly share code, notes, and snippets.

@cacheflow
Created March 24, 2022 03:27
Show Gist options
  • Save cacheflow/af013a40284de0c5512b19b6ef232463 to your computer and use it in GitHub Desktop.
Save cacheflow/af013a40284de0c5512b19b6ef232463 to your computer and use it in GitHub Desktop.
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', 'bugs@bunny.com');
console.log(testStudent);
if ( testStudent.name === 'Bugs Bunny' && testStudent.email === 'bugs@bunny.com') {
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