Liliana797979

1_holiday destinations - js advanced exam

Oct 22nd, 2021
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function addDestination () {
  2.     const html = {
  3.         city: document.getElementsByClassName('inputData')[0],
  4.         country: document.getElementsByClassName('inputData')[1],
  5.         seasons: document.getElementById(`seasons`),
  6.         outputE: document.getElementById('destinationsList'),
  7.     }
  8.  
  9.     function createRow (d, s) {
  10.         const rowE = document.createElement('tr')
  11.         const destination = document.createElement('td')
  12.         const season = document.createElement('td')
  13.  
  14.         destination.innerHTML = d
  15.         season.innerHTML = `${s[0].toLocaleUpperCase()}${s.slice(1)}`
  16.  
  17.         rowE.appendChild(destination)
  18.         rowE.appendChild(season)
  19.  
  20.         return rowE
  21.     }
  22.  
  23.     function updateSeason () {
  24.         const season = document.getElementById(html.seasons.value.toLocaleLowerCase())
  25.  
  26.         season.value = Number(season.value) + 1
  27.     }
  28.  
  29.     function clearInput () {
  30.         html.city.value = ''
  31.         html.country.value = ''
  32.         html.seasons.selected = 'Summer'
  33.     }
  34.  
  35.     function isValidInput () {
  36.         return html.city.value !== '' && html.country.value !== ''
  37.     }
  38.  
  39.     function getData () {
  40.         return [`${html.city.value}, ${html.country.value}`, html.seasons.value]
  41.     }
  42.  
  43.     if (isValidInput()) {
  44.         html.outputE.appendChild(createRow(...getData()))
  45.         updateSeason()
  46.         clearInput()
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment