Question: I need help with my JavaScript lab ------------------------------------------------------------------------------------------------------------ Lab 2 | COMP1073 Client-Side JavaScript Airports Beijing Capital International, https://goo.gl/maps/iPe5fAqzq8C2 PEK John F Kennedy International, https://goo.gl/maps/JWwABmA3MBS2
I need help with my JavaScript lab
------------------------------------------------------------------------------------------------------------
Airports
- Beijing Capital International, https://goo.gl/maps/iPe5fAqzq8C2 PEK
- John F Kennedy International, https://goo.gl/maps/JWwABmA3MBS2 JFK
- Lester B. Pearson International, https://goo.gl/maps/Ypu1dJLsnQu YYZ
- London Heathrow, https://goo.gl/maps/TFx8SrATdYr LHR
- Tokyo Haneda International, https://goo.gl/maps/5UxH2TxbRtT2 HND
// Get all the list items for the various airports
const airportListItems = document.getElementsByTagName('li');
// Create a new array to hold just the text in the list items
const airports = new Array();
// Loop through the list items, and for each one, extract the text and add it to the airports array
for(let i = 0; i < airportListItems.length; i++) {
airports.push(airportListItems[i].textContent);
}
// Delete all the existing list items so we can create new ones
const airportUL = document.querySelector('body ul');
airportUL.innerHTML = '';
// Loop through the airports array
for(let i = 0; i < airports.length; i++) {
const input = airports[i];
/* LAB 2: Put your own code here
-------------------------------------------------- */
// 1. Find the character index of the comma (use the above variable, input), and assign it to a variable called commaLocation
var commaLocation = data.indexOf(",");
// 2. Obtain the full name of the airport using the comma character index number as a reference point, and store it in a new variable (called airportName)
// 3. Capture the international airport code at the end of the string, and store it as a variable (called airportCode) (hint - you will need .length and .slice)
// 4. Get the Google Maps short URL from the string, using the character index number of the comma (use above variable, commaLocation), and store it as a variable, called googleUrl
// 5. Build a new string that is an HTML hyperlink, using the Google Maps URL (googleUrl) as the href, the airport code (airportCode), a dash (-), the airport name (airportName), and set it as the value of the result variable (let result = ...) (hint - use concatenation to build out each part of the HTML anchor element, taking care to use the right quotes)
let result =
/* ----------------------------------------------- */
// Create a new list item element
const listItem = document.createElement('li');
// Inject the new anchor element inside the list item element
listItem.innerHTML = result;
airportUL.appendChild(listItem);
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
