├── README.md ├── app.js ├── index.html └── styles.css /README.md: -------------------------------------------------------------------------------- 1 | # flight-widget-vanilla-javascript 2 | A Flight widget made in vanilla JavaScript just for fun! 3 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | const tableBody = document.getElementById('table-body') 2 | 3 | let flights = [ 4 | { 5 | time: "08:11", 6 | destination: "OMAN", 7 | flight: "OX 203", 8 | gate: "A 01", 9 | remarks: "ON TIME" 10 | }, 11 | { 12 | time: "12:39", 13 | destination: "LONDON", 14 | flight: "CL 320", 15 | gate: "C 31", 16 | remarks: "CANCELLED" 17 | }, 18 | { 19 | time: "13:21", 20 | destination: "DUBAI", 21 | flight: "DXB 201", 22 | gate: "A 19", 23 | remarks: "CANCELLED" 24 | }, 25 | { 26 | time: "14:01", 27 | destination: "FRANKFURT", 28 | flight: "FR 402", 29 | gate: "B 02", 30 | remarks: "ON TIME" 31 | }, 32 | { 33 | time: "15:22", 34 | destination: "TOKYO", 35 | flight: "TK 211", 36 | gate: "A 32", 37 | remarks: "DELAYED" 38 | } 39 | ] 40 | 41 | const destinations = ["TOKYO", "FRANKFURT", "DUBAI", "LONDON", "OMAN", "BEIRUT"] 42 | const remarks = ["ON TIME", "DELAYED", "CANCELLED"] 43 | let hour = 15 44 | 45 | function populateTable() { 46 | for (const flight of flights) { 47 | const tableRow = document.createElement("tr") 48 | const tableIcon = document.createElement("td") 49 | tableIcon.textContent = "✈" 50 | tableRow.append(tableIcon) 51 | 52 | for (const flightDetail in flight) { 53 | const tableCell = document.createElement("td") 54 | const word = Array.from(flight[flightDetail]) 55 | 56 | for (const [index, letter] of word.entries()) { 57 | const letterElement = document.createElement("div") 58 | setTimeout(() => { 59 | letterElement.classList.add('flip') 60 | letterElement.textContent = letter 61 | tableCell.append(letterElement) 62 | }, 100 * index) 63 | 64 | 65 | } 66 | tableRow.append(tableCell) 67 | } 68 | tableBody.append(tableRow) 69 | } 70 | } 71 | populateTable() 72 | 73 | 74 | 75 | function generateRandomLetter() { 76 | const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 77 | return alphabet.charAt(Math.floor(Math.random() * alphabet.length)) 78 | } 79 | 80 | function generateRandomNumber(maxNumber) { 81 | const numbers = "0123456789" 82 | if (maxNumber) { 83 | const newNumbers = numbers.slice(0, maxNumber) 84 | return newNumbers.charAt(Math.floor(Math.random() * newNumbers.length)) 85 | } else { 86 | return numbers.charAt(Math.floor(Math.random() * numbers.length)) 87 | } 88 | } 89 | 90 | function generateTime() { 91 | let displayHour = hour 92 | if (hour < 24) { 93 | hour++ 94 | } 95 | if (hour >= 24) { 96 | hour = 1 97 | displayHour = hour 98 | } 99 | if (hour < 10) { 100 | displayHour = "0" + hour 101 | } 102 | return displayHour + ":" + generateRandomNumber(5) + generateRandomNumber() 103 | } 104 | 105 | function shuffleUp() { 106 | flights.shift() 107 | flights.push({ 108 | time: generateTime(), 109 | destination: destinations[Math.floor(Math.random() * destinations.length)], 110 | flight: generateRandomLetter() + generateRandomLetter() + " " + generateRandomNumber() + generateRandomNumber() + generateRandomNumber(), 111 | gate: generateRandomLetter() + " " + generateRandomLetter() + generateRandomLetter(), 112 | remarks: remarks[Math.floor(Math.random() * remarks.length)] 113 | }) 114 | tableBody.textContent = "" 115 | populateTable() 116 | } 117 | 118 | 119 | setInterval(shuffleUp, 5000) 120 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |18 | | TIME | 19 |DESTINATION | 20 |FLIGHT | 21 |GATE | 22 |REMARKS | 23 |
---|