Advertisement
shady_obeyd

04.Airport Check

Feb 5th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let namePattern = /\s([A-Z][A-Za-z]*-[A-Z][A-Za-z]*(\.-[A-Z][A-Za-z]*\s|\s))/;
  3.     let airportPattern = /\s([A-Z]{3}\/[A-Z]{3})\s/;
  4.     let flightNumberPattern = /\s([A-Z]{1,3}\d{1,5})\s/;
  5.     let companyPattern = /-\s([A-Z][a-z]*\*[A-Z][a-z]*)\s/;
  6.  
  7.     let input = document.getElementById('str').value.split(',');
  8.  
  9.     let textToCheck = input[0];
  10.     let infoToDisplay = input[1].trim();
  11.  
  12.     let nameResult = textToCheck.match(namePattern)[1].trim().split('-').join(' ');
  13.     let airportResult = textToCheck.match(airportPattern)[1].trim().split('/').join(' to ');
  14.     let companyResult = textToCheck.match(companyPattern)[1].trim().split('*').join(' ');
  15.     let flightResult = textToCheck.match(flightNumberPattern)[1].trim();
  16.  
  17.     let output;
  18.  
  19.     if(infoToDisplay === 'all'){
  20.         output = `Mr/Ms, ${nameResult}, your flight number ${flightResult} is from ${airportResult}. Have a nice flight with ${companyResult}.`
  21.     } else if(infoToDisplay === 'flight'){
  22.         output = `Your flight number ${flightResult} is from ${airportResult}.`;
  23.     } else if(infoToDisplay === 'company'){
  24.         output = `Have a nice flight with ${companyResult}.`;
  25.     } else if (infoToDisplay === 'name'){
  26.         output = `Mr/Ms, ${nameResult}, have a nice flight!`;
  27.     }
  28.  
  29.     let resultElement = document.getElementById('result');
  30.     resultElement.textContent = output;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement