97 lines
2.9 KiB
JavaScript
97 lines
2.9 KiB
JavaScript
function Student(name, age, grade) {
|
|
this.name = name,
|
|
this.age = age,
|
|
this.grade = grade
|
|
};
|
|
|
|
function Car(brand, model, year, isElectric) {
|
|
this.brand = brand,
|
|
this.model = model,
|
|
this.year = year,
|
|
this.isElectric = isElectric,
|
|
this.describe = function() {
|
|
console.log(`This is a ${this.year} ${this.brand} ${this.model}`);
|
|
}
|
|
};
|
|
|
|
function House(type, bedrooms, price) {
|
|
this.type = type;
|
|
this.bedrooms = bedrooms;
|
|
this.price = price;
|
|
}
|
|
|
|
function Employee(name, position, salary) {
|
|
this.name = name,
|
|
this.position = position,
|
|
this.salary = salary,
|
|
this.increaseSalary = function(amount) {
|
|
this.salary += amount;
|
|
}
|
|
}
|
|
|
|
function Movie(title, genre, rating) {
|
|
this.title = title,
|
|
this.genre = genre,
|
|
this.rating = rating,
|
|
this.rateMovie = function(newRating) {
|
|
this.rating = newRating;
|
|
}
|
|
}
|
|
|
|
function Course(courseName, instructor, schedule) {
|
|
this.courseName = courseName;
|
|
this.instructor = instructor;
|
|
this.schedule = schedule;
|
|
}
|
|
|
|
var student1 = new Student("Levi McLean", 20, 99);
|
|
var student2 = new Student("Tyler Hird", 19, 88);
|
|
var student3 = new Student("Joe Jefferson", 21, 75);
|
|
|
|
var car1 = new Car("Tesla", "Model 3", 2025, true);
|
|
var car2 = new Car("Ford", "F-150", 2020, false);
|
|
|
|
var house1 = new House("Bungalow", 2, 250000);
|
|
var house2 = new House("Town House", 3, 375000);
|
|
|
|
var employee1 = new Employee("Jimmy Joe", "Manager", 80000);
|
|
|
|
var movie1 = new Movie("Kill Bill", "Action", 4.4);
|
|
var movie2 = new Movie("Star Wars", "Action", 3.7);
|
|
|
|
console.log(student1.name + " " + student1.grade);
|
|
console.log(student2.name + " " + student2.grade);
|
|
console.log(student3.name + " " + student3.grade);
|
|
|
|
if (car1.isElectric === true) {
|
|
console.log(`${car1.brand} ${car1.model} is an electric car!`)
|
|
} if (car2.isElectric === true) {
|
|
console.log(`${car2.brand} ${car2.model} is an electric car!`)
|
|
}
|
|
|
|
car1.describe();
|
|
car2.describe();
|
|
|
|
console.log(`The ${house1.type} has ${house1.bedrooms} bedrooms and costs $${house1.price}`);
|
|
console.log(`The ${house2.type} has ${house2.bedrooms} bedrooms and costs $${house2.price}`);
|
|
|
|
console.log(`Previous ${employee1.position} salary: $${employee1.salary}.`);
|
|
console.log("Increasing salary by $1000000");
|
|
employee1.increaseSalary(1000000);
|
|
console.log(`New ${employee1.position} salary: $${employee1.salary}.`);
|
|
|
|
console.log(`Previous rating for ${movie1.title}: ${movie1.rating}`);
|
|
console.log(`Previous rating for ${movie2.title}: ${movie2.rating}`);
|
|
movie1.rateMovie(5);
|
|
console.log(`New rating for ${movie1.title}: ${movie1.rating}`);
|
|
console.log(`New rating for ${movie2.title}: ${movie2.rating}`);
|
|
|
|
var courseSchedule = {
|
|
day: "Monday",
|
|
time: "10:00 AM",
|
|
location: "Room 101"
|
|
};
|
|
|
|
var course1 = new Course("JavaScript 1", "Mr. Smith", courseSchedule);
|
|
|
|
console.log(`The ${course1.courseName} course is taught by ${course1.instructor} on ${course1.schedule.day} at ${course1.schedule.time} in ${course1.schedule.location}`) |