Advertisement
igrilkul

Untitled

Jul 24th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function attachEvents() {
  2.     let locat=$('#location');
  3.     $('#submit').on('click',function getLocations(){
  4.         if(locat.val().length>0)
  5.         {
  6.  
  7.             $.ajax({
  8.                 url:'https://judgetests.firebaseio.com/locations.json',
  9.                 method:'GET',
  10.                 success:displayForecasts,
  11.                 error: ()=>{
  12.                     console.log('error')
  13.                 }
  14.             });
  15.         }
  16.     });
  17.  
  18.  
  19.  
  20.  
  21.     function displayForecasts(locations)
  22.     {
  23.         let code;
  24.         for (let i = 0; i < locations.length; i++) {
  25.             if(locations[i].name===locat.val())
  26.             {
  27.                 code=locations[i].code;
  28.             }
  29.         }
  30.  
  31.         (function f1() {
  32.             $.ajax({
  33.                 url:`https://judgetests.firebaseio.com/forecast/today/${code}.json`,
  34.                 method:'GET',
  35.                 success:currentConditions,
  36.                 error: ()=>{
  37.                     console.log('error')
  38.                 }
  39.             });
  40.         })();
  41.  
  42.         (function  f2() {
  43.             $.ajax({
  44.                 url:`https://judgetests.firebaseio.com/forecast/upcoming/${code}.json`,
  45.                 method:'GET',
  46.                 success:upcoming,
  47.                 error: ()=>{
  48.                     console.log('error')
  49.                 }
  50.             });
  51.         })();
  52.     }
  53.  
  54.     function currentConditions(obj)
  55.     {
  56.         let condition = obj.forecast.condition;
  57.         let weatherSymbol;
  58.         let degreesSymbol='&#176';
  59.         let temperature = obj.forecast.low + degreesSymbol + '/' + obj.forecast.high + degreesSymbol;
  60.         switch (condition)
  61.         {
  62.             case 'Sunny': weatherSymbol='&#x2600'; break;
  63.             case 'Partly sunny': weatherSymbol='&#x26C5'; break;
  64.             case 'Overcast': weatherSymbol='&#x2601'; break;
  65.             case 'Rain': weatherSymbol='&#x2614'; break;
  66.         }
  67.         console.log(weatherSymbol);
  68.         let current = $('#current');
  69.         current
  70.             .append($('<span class="condition symbol">)').text(weatherSymbol))
  71.             .append($('<span class="condition">')
  72.                 .append($('<span class="forecast-data">').text(obj.name))
  73.                 .append($('<span class="forecast-data">').text(temperature))
  74.                 .append($('<span class="forecast-data">').text(obj.forecast.condition))
  75.             );
  76.         $('#forecast').css('display','block');
  77.     }
  78.  
  79.     function upcoming(obj)
  80.     {
  81.         console.log('hi');
  82.         let threeDaysGrace=$('#upcoming');
  83.         let weatherSymbol;
  84.         let degreesSymbol='&#176';
  85.         for(let j=0;j<obj.length;j++)
  86.         {
  87.             console.log('h');
  88.             let condition = obj[i].forecast.condition;
  89.             let temperature = obj[i].forecast.low + degreesSymbol + '/' + obj[i].forecast.high + degreesSymbol;
  90.             switch (condition)
  91.             {
  92.                 case 'Sunny': weatherSymbol='&#x2600'; break;
  93.                 case 'Partly sunny': weatherSymbol='&#x26C5'; break;
  94.                 case 'Overcast': weatherSymbol='&#x2601'; break;
  95.                 case 'Rain': weatherSymbol='&#x2614'; break;
  96.             }
  97.             console.log(weatherSymbol);
  98.  
  99.             threeDaysGrace
  100.                 .append($('<span class="upcoming">')
  101.                     .append($('<span class="symbol">)').text(weatherSymbol))
  102.                     .append($('<span class="forecast-data">').text(temperature))
  103.                     .append($('<span class="forecast-data">').text(condition))
  104.  
  105.                 );
  106.             $('#forecast').css('display','block');
  107.         }
  108.         }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement