Created
April 13, 2019 23:29
-
-
Save amfischer/3215777db5b06ee8e0b4c4155bd4913b to your computer and use it in GitHub Desktop.
Karlas google apps script
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
function course(seats, name) { | |
this.seats = seats | |
this.enrolled = 0 | |
this.name = name | |
this.increment = function() { | |
this.enrolled++ | |
} | |
this.isFull = function() { | |
return this.enrolled >= this.seats | |
} | |
} | |
var puzzles = new course(30, 'Puzzles and Games') | |
var studyHall = new course(30, 'Study Hall/Doodling') | |
var csi = new course(30, 'Crime scene investigation') | |
var pe = new course(30, 'Physical education') | |
function findCourseObject(name) { | |
switch (name) { | |
case 'Puzzles and Games': | |
return puzzles | |
case 'Study Hall/Doodling': | |
return studyHall | |
case 'Crime scene investigation': | |
return csi | |
case 'Physical education': | |
return pe | |
} | |
} | |
var choices = { | |
one: { | |
course: findCourseObject('Puzzles and Games'), | |
taken: false | |
}, | |
two: { | |
course: findCourseObject('Study Hall/Doodling'), | |
taken: false | |
}, | |
three: { | |
course: findCourseObject('Crime scene investigation'), | |
taken: false | |
}, | |
four: { | |
course: findCourseObject('Physical education'), | |
taken: false | |
} | |
} | |
var currentSession = '' | |
for (let c in choices) { | |
if (!choices[c].taken && !choices[c].course.isFull() && currentSession === '') { | |
currentSession = choices[c].course.name | |
choices[c].course.increment() | |
choices[c].taken = true | |
break | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment