WDV 221 Intro to JavaScript
JavaScript Objects
Use the following parallel arrays to create a set of objects:
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" ];
For you assignment:
Part 1
- Create a class called masterBook that defines three properties: bookTitle, bookPrice, bookAuthor
- In the masterBook class define a method call studentDiscountPrice( ). The method will return the bookPrice discounted by 20%. The return value should be formatted as currency.
- On your page create the javascript parallel arrays shown above.
- Create a script that will create and load three book objects from the masterBook class called book1, book2, book3 using the data from the parallel arrays.
- Display the contents of each book object on the console.
- Create a Javascript array called javascriptBooks. Load the book objects into the array.
- Use a loop to process the contents of the javascriptBooks array. Display all the information for each book on the web page. This includes calling the studentDiscountPrice( ).
(results go here)
Part 2
- Create a script that will create and load three book objects called bookA, bookB, bookC using the object literal { } method. Use the same properties and methods from Part 1.
- Display the contents of each book object on the console.
- Create a JavaScript array called newBooks. Load these book objects into the array.
- Use a loop to process the contents of the newBooks array. Display all information for each book on the web page. This includes calling the studentDiscountPrice( ).