Files
2026-01-19 21:02:18 -05:00

60 lines
2.4 KiB
HTML

<html>
<head>
<title>Levi McLean Lab 1</title>
<script language="JavaScript" type="text/JavaScript">
// VideoType constructor
function VideoType(title, category, cast, price) {
this.title = title;
this.category = category;
this.cast = cast;
this.price = price;
this.numRents = 0;
this.vidRevenue = 0.0;
}
// procRental method
VideoType.prototype.procRental = function() {
this.numRents++;
this.vidRevenue += this.price;
VideoType.totRevenue += this.price;
}
// Variable to hold total revenue
VideoType.totRevenue = 0.0;
// Function to create video array on window load
function StartMeUp() {
var videos = [];
// Create three VideoType objects
videos[0] = new VideoType("Fear and Loathing in Las Vegas", "Comedy", ["Johnny Depp", "Benicio Del Toro"], 3.99);
videos[1] = new VideoType("The Matrix", "Sci-Fi", ["Keanu Reeves", "Laurence Fishburne"], 4.99);
videos[2] = new VideoType("The Lion King", "Animation", ["Matthew Broderick", "Jeremy Irons"], 2.99);
for (var i = 0; i < 5; i++) {
for (var j = 0; j < videos.length; j++) {
videos[j].procRental();
}
}
// Print info about each video
for (var k = 0; k < videos.length; k++) {
document.write("Title: " + videos[k].title + "<br>");
document.write("Category: " + videos[k].category + "<br>");
document.write("Cast: " + videos[k].cast.join(", ") + "<br>");
document.write("Price: $" + videos[k].price + "<br>");
document.write("Number of rents: " + videos[k].numRents + "<br>");
document.write("Revenue for this video: $" + videos[k].vidRevenue.toFixed(2) + "<br><br>");
}
document.write("Total Revenue for all videos: $" + VideoType.totRevenue.toFixed(2) + "<br>");
}
// Call StartMeUp on window load
window.onload = StartMeUp;
</script>
</head>
<body>
</body>
</html>