Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function attachEvents() {
- let locat=$('#location');
- $('#submit').on('click',function getLocations(){
- if(locat.val().length>0)
- {
- $.ajax({
- url:'https://judgetests.firebaseio.com/locations.json',
- method:'GET',
- success:displayForecasts,
- error: ()=>{
- console.log('error')
- }
- });
- }
- });
- function displayForecasts(locations)
- {
- let code;
- for (let i = 0; i < locations.length; i++) {
- if(locations[i].name===locat.val())
- {
- code=locations[i].code;
- }
- }
- (function f1() {
- $.ajax({
- url:`https://judgetests.firebaseio.com/forecast/today/${code}.json`,
- method:'GET',
- success:currentConditions,
- error: ()=>{
- console.log('error')
- }
- });
- })();
- (function f2() {
- $.ajax({
- url:`https://judgetests.firebaseio.com/forecast/upcoming/${code}.json`,
- method:'GET',
- success:upcoming,
- error: ()=>{
- console.log('error')
- }
- });
- })();
- }
- function currentConditions(obj)
- {
- let condition = obj.forecast.condition;
- let weatherSymbol;
- let degreesSymbol='°';
- let temperature = obj.forecast.low + degreesSymbol + '/' + obj.forecast.high + degreesSymbol;
- switch (condition)
- {
- case 'Sunny': weatherSymbol='☀'; break;
- case 'Partly sunny': weatherSymbol='⛅'; break;
- case 'Overcast': weatherSymbol='☁'; break;
- case 'Rain': weatherSymbol='☔'; break;
- }
- console.log(weatherSymbol);
- let current = $('#current');
- current
- .append($('<span class="condition symbol">)').text(weatherSymbol))
- .append($('<span class="condition">')
- .append($('<span class="forecast-data">').text(obj.name))
- .append($('<span class="forecast-data">').text(temperature))
- .append($('<span class="forecast-data">').text(obj.forecast.condition))
- );
- $('#forecast').css('display','block');
- }
- function upcoming(obj)
- {
- console.log('hi');
- let threeDaysGrace=$('#upcoming');
- let weatherSymbol;
- let degreesSymbol='°';
- for(let j=0;j<obj.length;j++)
- {
- console.log('h');
- let condition = obj[i].forecast.condition;
- let temperature = obj[i].forecast.low + degreesSymbol + '/' + obj[i].forecast.high + degreesSymbol;
- switch (condition)
- {
- case 'Sunny': weatherSymbol='☀'; break;
- case 'Partly sunny': weatherSymbol='⛅'; break;
- case 'Overcast': weatherSymbol='☁'; break;
- case 'Rain': weatherSymbol='☔'; break;
- }
- console.log(weatherSymbol);
- threeDaysGrace
- .append($('<span class="upcoming">')
- .append($('<span class="symbol">)').text(weatherSymbol))
- .append($('<span class="forecast-data">').text(temperature))
- .append($('<span class="forecast-data">').text(condition))
- );
- $('#forecast').css('display','block');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement