Created
October 31, 2013 16:17
-
-
Save brycelambert/7252506 to your computer and use it in GitHub Desktop.
javascript course app
This file contains 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
var CourseApp = { | |
students: [], | |
courses: [], | |
teachers: [], | |
render_item: function(item, type) { | |
var html = this.render_html(item, type); | |
document.getElementById(type + "-list").innerHTML += html; | |
}, | |
render_items: function(items_name) { | |
var items = this[items_name]; | |
var i = 0; for(; i < items.length;) { | |
this.render_item(items[i], items_name); | |
i = i + 1; | |
} | |
}, | |
render_html: function(item, type) { | |
return "<li id=\'" + item.name + "\' class=\'" + type + "\'>" + | |
"<h4>" + item.name + "</h4>" + "</li>" | |
} | |
}; | |
///////////// | |
var Student = function(name, major) { | |
this.name = name; | |
this.major = major; | |
CourseApp.students.push(this); | |
}; | |
var Teacher = function(name, specialization) { | |
this.name = name; | |
this.specialization = specialization; | |
CourseApp.teachers.push(this); | |
}; | |
var Course = function(name, department, day) { | |
this.name = name, | |
this.department = department, | |
this.day = day, | |
CourseApp.courses.push(this); | |
}; | |
new Student('Stacy', 'Geology'); | |
new Teacher('Tom', 'ruby'); | |
CourseApp.render_items("teachers") | |
CourseApp.render_items("students") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment