Task 1
In a new tab navigate to the Hacker News webpage, and open the Chrome Dev console (Command + Option + J).
We will write our JavaScript code in the console.
The anchor links which include the topic names have the class storylink
. We can use this to target and select only those elements. We can use the following code:
let titles = document.getElementsByClassName("storylink");
Task 2:
Now create a for loop that prints the innerHTML
of each title element
Task 3:
Now create a for loop that iterates over the same items and prints the href
link values of each title element. To get the href
value of an element you have to use the getAttribute
method.