import { Component, OnInit, ViewEncapsulation } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], encapsulation: ViewEncapsulation.None }) export class AppComponent implements OnInit { ngOnInit(): void { let Tolkien = '
The Hobbit
The Lord of the Rings
The Silmarillion
'; let Brooks = '
The Sword of Shannara
The Elfstones of Shannara
The Wishsong of Shannara
Running with the Demon
A Knight of the Word
Angel Fire East
'; let Rowling = '
Harry Potter and the Philosopher's Stone
Harry Potter and the Chamber of Secrets
Harry Potter and the Prisoner of Azkaban
Harry Potter and the Goblet of Fire
Harry Potter and the Order of the Phoenix
Harry Potter and the Half-Blood Prince
Harry Potter and the Deathly Hallows
'; let Wells = '
The Time Machine
The War of the Worlds
'; let Green = '
Deathstalker
Deathstalker Rebellion
Deathstalker War
Deathstalker Honor
Deathstalker Destiny
'; let Lovecraft = '
The Call of Cthulhu
At the Mountains of Madness
'; let King = '
Carrie
Night Shift
It
The Dark Half
'; let liTags = document.getElementsByTagName('LI'); document.getElementById('bookShelf').innerHTML = Tolkien; let booksNum = 0; let addToShoppingCart = () => { booksNum += 1; document.getElementById('text').innerHTML = 'Added ' + booksNum + (booksNum == 1 ? ' book' : ' books') + ' to shopping cart.' }; let booksImages = document.getElementsByClassName('book'); for (var j = 0; j < booksImages.length; j++) { booksImages[j].getElementsByTagName('IMG')[0].addEventListener('click', addToShoppingCart); (booksImages[j].getElementsByTagName('IMG')[0]).style.cursor = 'pointer'; } for (let i = 0; i < liTags.length; i++) { liTags[i].addEventListener('click', () => { let bookShelf = document.getElementById('bookShelf'); switch (i) { case 0: bookShelf.innerHTML = Tolkien; break; case 1: bookShelf.innerHTML = Brooks; break; case 2: bookShelf.innerHTML = Rowling; break; case 3: bookShelf.innerHTML = Wells; break; case 4: bookShelf.innerHTML = Green; break; case 5: bookShelf.innerHTML = Lovecraft; break; case 6: bookShelf.innerHTML = King; break; }; booksImages = document.getElementsByClassName('book'); for (var j = 0; j < booksImages.length; j++) { booksImages[j].getElementsByTagName('IMG')[0].addEventListener('click', addToShoppingCart); (booksImages[j].getElementsByTagName('IMG')[0]).style.cursor = 'pointer'; } }); } } }