Created
May 13, 2020 17:38
-
-
Save enijaward/a51729cf1a04bbe6fea15a12dcb408d8 to your computer and use it in GitHub Desktop.
Assignment 3: Introduction to Javascript
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Homework 3</title> | |
</head> | |
<body> | |
<div> | |
<h1>Books Galore!</h1> | |
<h2>Here's what we have: </h2> | |
<p id="book1"></p> | |
<p id="book2"></p> | |
</div> | |
<script src="js/hw3.js"></script> | |
</body> | |
</html> |
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
// creates object template | |
function Books(name, available, sold) { | |
this.name = name; | |
this.available = available; | |
this.sold = sold; | |
// function to subtract the amount sold from what is available | |
this.checkAvailability = function() { | |
return this.available - this.sold; | |
}; | |
} | |
// creates object instances | |
var firstBook = new Books('Methods of Persuasion by Nick Kolenda', 12, 5); | |
var secondBook = new Books('Milk and Honey by Rupi Kaur', 20, 7); | |
// displays the properties, values, and method onto screen for books one and two | |
var productInfo = firstBook.name + ' available: '; | |
productInfo += firstBook.checkAvailability(); | |
var elBook = document.getElementById('book1'); | |
elBook.textContent = productInfo; | |
var productInfo = secondBook.name + ' available: '; | |
productInfo += secondBook.checkAvailability(); | |
var elBook = document.getElementById('book2'); | |
elBook.textContent = productInfo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment