Skip to content

Instantly share code, notes, and snippets.

@amfischer
Created Apr 13, 2019
Embed
What would you like to do?
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