Changed around line 1
+ const flightList = document.getElementById('flight-list');
+ const trackBtn = document.getElementById('track-btn');
+ const sortSelect = document.getElementById('sort');
+
+ let flights = [];
+
+ function addFlight(origin, destination, price) {
+ const flight = {
+ id: Date.now(),
+ origin,
+ destination,
+ price,
+ date: new Date().toLocaleString()
+ };
+ flights.push(flight);
+ renderFlights();
+ }
+
+ function renderFlights() {
+ const sortedFlights = sortFlights();
+ flightList.innerHTML = sortedFlights.map(flight => `
+
+
+ ${flight.origin} → ${flight.destination}
+
+
+ `).join('');
+ }
+
+ function sortFlights() {
+ const sortValue = sortSelect.value;
+ return [...flights].sort((a, b) => {
+ if (sortValue === 'price-asc') return a.price - b.price;
+ if (sortValue === 'price-desc') return b.price - a.price;
+ return new Date(b.date) - new Date(a.date);
+ });
+ }
+
+ trackBtn.addEventListener('click', () => {
+ const origin = document.getElementById('origin').value;
+ const destination = document.getElementById('destination').value;
+ const price = Math.floor(Math.random() * 500) + 100; // Simulated price
+ if (origin && destination) {
+ addFlight(origin, destination, price);
+ }
+ });
+
+ sortSelect.addEventListener('change', renderFlights);
+
+ // Initial data
+ addFlight('New York (JFK)', 'London (LHR)', 450);
+ addFlight('Los Angeles (LAX)', 'Tokyo (NRT)', 850);
+ addFlight('Chicago (ORD)', 'Paris (CDG)', 600);