-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusePrototype.html
More file actions
31 lines (31 loc) · 1.14 KB
/
Copy pathusePrototype.html
File metadata and controls
31 lines (31 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Book Custom Object</title>
<script type="text/javascript" src="book.js"></script>
</head>
<body>
<h2>CIW JavaScript Specialist</h2>
<h3>Book Custom Object</h3>
<script type="text/javascript">
//referring Book object, adding to the prototype the method called addTax()
Book.prototype.addTax = function addTax() {
var taxAdded = this.price * 1.18;
return (taxAdded.toFixed(2))
//again, we added addTax method under Book object by using prototype feature
};
//define two instance of Book object pass parameter (theTitle,theAuthor,thePrice)
var famousBook = new Book('War and Peace',
'Leo Tolstoy',30.00);
var myBook = new Book('JavaScript by Example',
'Ellie Quigley',25);
document.write(famousBook.show()+'<br/>');
document.write(myBook.show()+'<br/>');
document.write('With tax '+ famousBook.title +
' costs ' + famousBook.addTax() + '<br/>');
document.write('With tax ' + myBook.title +
' costs ' + myBook.addTax() + '<br/>');
</script>
</body>
</html>