Advertisement
GeorgiLukanov87

01. Travel Agency - JS Advanced Final Exam - 27 June 2021

Mar 24th, 2023 (edited)
1,105
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 01. Travel Agency
  2. // JS Advanced Final Exam - 27 June 2021
  3. // https://judge.softuni.org/Contests/Practice/Index/3008#0
  4.  
  5. function solution() {
  6.   const fnameElement = document.getElementById('fname');
  7.   const emailElement = document.getElementById('email');
  8.   const phoneElement = document.getElementById('phone');
  9.   const addressElement = document.getElementById('address');
  10.   const codeElement = document.getElementById('code');
  11.   const mainContainer = document.getElementById('block');
  12.  
  13.   const infoPreview = document.getElementById('infoPreview');
  14.  
  15.   const submitBtn = document.getElementById('submitBTN');
  16.   const editBtn = document.getElementById('editBTN');
  17.   const continueBtn = document.getElementById('continueBTN');
  18.  
  19.   submitBtn.addEventListener('click', submitInfo);
  20.   editBtn.addEventListener('click', editHandler);
  21.   continueBtn.addEventListener('click', continueHandler);
  22.  
  23.   let data = {}
  24.   function submitInfo() {
  25.     data = {
  26.       fname: fnameElement.value,
  27.       email: emailElement.value,
  28.       phone: phoneElement.value,
  29.       address: addressElement.value,
  30.       code: codeElement.value,
  31.     }
  32.     if (data.fname == '' || data.email == '') {
  33.       return;
  34.     }
  35.  
  36.     customLiElement('li', data.fname, 'Full Name:', infoPreview);
  37.     customLiElement('li', data.email, 'Email:', infoPreview);
  38.     customLiElement('li', data.phone, 'Phone Number:', infoPreview);
  39.     customLiElement('li', data.address, 'Address:', infoPreview);
  40.     customLiElement('li', data.code, 'Postal Code:', infoPreview);
  41.  
  42.     submitBtn.disabled = true;
  43.     editBtn.disabled = false;
  44.     continueBtn.disabled = false;
  45.     clearInputs();
  46.   }
  47.  
  48.   function editHandler() {
  49.     fnameElement.value = data.fname;
  50.     emailElement.value = data.email;
  51.     phoneElement.value = data.phone;
  52.     addressElement.value = data.address;
  53.     codeElement.value = data.code;
  54.  
  55.     submitBtn.disabled = false;
  56.     editBtn.disabled = true;
  57.     continueBtn.disabled = true;
  58.     Array.from(infoPreview.querySelectorAll('li')).forEach(li => {
  59.       li.remove();
  60.     })
  61.   }
  62.  
  63.   function continueHandler() {
  64.     console.log(mainContainer)
  65.  
  66.     mainContainer.innerHTML = ''
  67.     console.log(mainContainer)
  68.     let finalMsgH3 = document.createElement('h3');
  69.     finalMsgH3.textContent = "Thank you for your reservation!";
  70.     mainContainer.appendChild(finalMsgH3);
  71.   }
  72.  
  73.   function customLiElement(type, content, extraInfo, parent) {
  74.     let newElement = document.createElement(type);
  75.     newElement.textContent = `${extraInfo} ${content}`;
  76.     parent.appendChild(newElement);
  77.     return newElement;
  78.   }
  79.  
  80.   function clearInputs() {
  81.     fnameElement.value = '';
  82.     emailElement.value = '';
  83.     phoneElement.value = '';
  84.     addressElement.value = '';
  85.     codeElement.value = '';
  86.   }
  87.  
  88.  
  89. }
  90.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement