Skip to content

Instantly share code, notes, and snippets.

@amfischer
Created April 13, 2019 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amfischer/3215777db5b06ee8e0b4c4155bd4913b to your computer and use it in GitHub Desktop.
Save amfischer/3215777db5b06ee8e0b4c4155bd4913b to your computer and use it in GitHub Desktop.
Karlas google apps script
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