-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjsObjects.html
More file actions
66 lines (62 loc) · 2.87 KB
/
jsObjects.html
File metadata and controls
66 lines (62 loc) · 2.87 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
let bookTitles = ["Beginning Javascript", "Logic with ES6", "Javascript Ojbects Made Easy"];
let bookPrices = [19.99, 29.49, 999.99];
let bookAuthor = ["Smith", "Johson-Parker", "Westin" ];
let book1 = {
bookName: bookTitles[0],
bookPrice: bookPrices[0],
bookAuthor: bookAuthor[0],
studentDiscountPrice: function() {
return Intl.NumberFormat('en-us',{
style: 'currency',
currency: 'USD'
}).format(this.bookPrice * .8);
}
}
let book2 = {
bookName: bookTitles[1],
bookPrice: bookPrices[1],
bookAuthor: bookAuthor[1],
studentDiscountPrice: function() {
return Intl.NumberFormat('en-us',{
style: 'currency',
currency: 'USD'
}).format(this.bookPrice * .8);
}
}
let book3 = {
bookName: bookTitles[2],
bookPrice: bookPrices[2],
bookAuthor: bookAuthor[2],
studentDiscountPrice: function() {
return Intl.NumberFormat('en-us',{
style: 'currency',
currency: 'USD'
}).format(this.bookPrice * .8);
}
}
let javascriptBooks = [book1, book2, book3];
</script>
</head>
<body>
<h1>Displaying books using book objects</h1>
<script>
document.write("<p>Title: " + book1.bookName + "</p>" + "<p>Author: " + book1.bookAuthor + "</p>" + "<p>Price: $" + book1.bookPrice + "</p>" + "<p>Discounted Price: " + book1.studentDiscountPrice() + "</p></br>")
document.write("<p>Title: " + book2.bookName + "</p>" + "<p>Author: " + book2.bookAuthor + "</p>" + "<p>Price: $" + book2.bookPrice + "</p>" + "<p>Discounted Price: " + book2.studentDiscountPrice() + "</p></br>")
document.write("<p>Title: " + book3.bookName + "</p>" + "<p>Author: " + book3.bookAuthor + "</p>" + "<p>Price: $" + book3.bookPrice + "</p>" + "<p>Discounted Price: " + book3.studentDiscountPrice() + "</p></br>")
</script>
<h1>Displaying books from array using loop</h1>
<script>
for (let index = 0; index < javascriptBooks.length; index++) {
document.write("<p>Title: " + javascriptBooks[index].bookName + "</p>" + "<p>Author: " + javascriptBooks[index].bookAuthor + "</p>" + "<p>Price: $" + javascriptBooks[index].bookPrice + "</p>" + "<p>Discounted Price: " + javascriptBooks[index].studentDiscountPrice() + "</p></br>")
}
</script>
</body>
</html>