Skip to content

Instantly share code, notes, and snippets.

@brycelambert
Created October 31, 2013 16:17
Show Gist options
  • Save brycelambert/7252506 to your computer and use it in GitHub Desktop.
Save brycelambert/7252506 to your computer and use it in GitHub Desktop.
javascript course app
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