Given the array below, provide the JS code to loop through the array and print each item to the console prepended by "Harry Potter and the "
var books = [ "Philosopher's Stone (1997)", "Chamber of Secrets (1998)", "Prisoner of Azkaban (1999)", "Goblet of Fire (2000)", "Order of the Phoenix (2003)", "Half-Blood Prince (2005)", "Deathly Hallows (2007)" ]
The console output should be:
Harry Potter and the Philosopher's Stone (1997)
Harry Potter and the Chamber of Secrets (1998)
Harry Potter and the Prisoner of Azkaban (1999)
Harry Potter and the Goblet of Fire (2000)
Harry Potter and the Order of the Phoenix (2003)
Harry Potter and the Half-Blood Prince (2005)
Harry Potter and the Deathly Hallows (2007)
var books = [ "Philosopher's Stone (1997)", "Chamber of Secrets (1998)", "Prisoner of Azkaban (1999)", "Goblet of Fire (2000)", "Order of the Phoenix (2003)", "Half-Blood Prince (2005)", "Deathly Hallows (2007)" ] for (var i = 0; i < books.length; i++) { console.log("Harry Potter and the " + books[i]); }
Get Answers For Free
Most questions answered within 1 hours.