Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Show the Local Weather example broken #133

Closed
aw1231 opened this issue Jul 13, 2017 · 6 comments
Closed

Show the Local Weather example broken #133

aw1231 opened this issue Jul 13, 2017 · 6 comments

Comments

@aw1231
Copy link

aw1231 commented Jul 13, 2017

Issue Description

When you open the codepen the example looks broken.

Browser Information

I am running the latest verions of Windows 10 and Chrome

  • Browser Name, Version: Chrome 59.0.3071.115
  • Operating System: Windows 10
  • Mobile, Desktop, or Tablet: Desktop

Your Code / Link to Your Pen

https://codepen.io/freeCodeCamp/full/bELRjV

Screenshot

2017-07-13

@marigerr
Copy link
Contributor

There was a recent commit on the non-beta version of FCC that made changes to the Local Weather App challenge : Add glitch API to Front-End weather project
There is a closed issue where @MiloATH stated there was a need to update the codepen with the new glitch API, but it hasn't been done yet.
It looks like that issue might need to be re-opened.

This repo testable-projects-fcc doesn't cover the Local Weather App challenge as it's not part of the beta version of FCC.

@MiloATH
Copy link

MiloATH commented Jul 14, 2017

I forked and updated the codepen. It can be found here. The only thing that needs to be updated in the freeCodeCamp pen is the javascript. It would be great if the freeCodeCamp pen could be updated @QuincyLarson. Here is the updated javascript:

var app = angular.module('Weather', []);

app.factory('WeatherApi', function($http) {
  var obj = {};
  
  obj.getLoc = function() {
    return $http.jsonp("https://ipinfo.io/json?callback=JSON_CALLBACK");
  };
  obj.getCurrent = function(loc) {
    var api = "https://fcc-weather-api.glitch.me/api/current?";
    loc = loc.split(",");
    var lat = "lat=" + loc[0];
    var lon = "&lon=" + loc[1];
    var cb = "&callback=JSON_CALLBACK";
    return $http.jsonp(api + lat + lon + cb);
  };
  return obj
});

app.controller('MainCtrl', function($scope, WeatherApi) {
  $scope.Data = {};
  $scope.Data.unit ='C';
  $scope.Data.sysChange = false;
  WeatherApi.getLoc().success(function(data) {
    var city = data.loc + ',' + data.country;
    $scope.Data.city = data.city;
    $scope.Data.country = data.country;
    WeatherApi.getCurrent(data.loc).success(function(data) {
      CurrentWeather(data)
    });
  });

  function CurrentWeather(data) {
    $scope.Data.temp = Math.round(data.main.temp);
    $scope.Data.Cel = Math.round(data.main.temp);
    $scope.Data.des = data.weather[0].main;
    $scope.Data.Fah = Math.round( ($scope.Data.temp * 9)/5 + 32 );
    return IconGen($scope.Data.des);
  }

  function IconGen(city) {
    var city = city.toLowerCase()
    switch (city) {
      case 'drizzle':
        addIcon(city)
        break;
      case 'clouds':
        addIcon(city)
        break;
      case 'rain':
        addIcon(city)
        break;
      case 'snow':
        addIcon(city)
        break;
      case 'clear':
        addIcon(city)
        break;
      case 'thunderstom':
        addIcon(city)
        break;
      default:
    $('div.clouds').removeClass('hide');
    }
  }

  function addIcon(city) {
    $('div.' + city).removeClass('hide');
  }
  
  $scope.Data.sys= function(){
   if($scope.Data.sysChange){
     $scope.Data.unit ='C';
     $scope.Data.temp = $scope.Data.Cel;
     return $scope.Data.sysChange = false;
     }
    $scope.Data.unit ='F';
    $scope.Data.temp = $scope.Data.Fah;
    return $scope.Data.sysChange = true;
  }
  
  
});

@aw1231
Copy link
Author

aw1231 commented Jul 14, 2017

@marigerr would you like me close this issue and ask that freeCodeCamp/freeCodeCamp#15598 be reopened?

@marigerr
Copy link
Contributor

@aw1231 I'm new to contributing, but that seems like a good idea to try to reopen #15598 and finish resolving there.
Thanks for the further info @MiloATH !

@aw1231
Copy link
Author

aw1231 commented Jul 14, 2017

Will do.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@aw1231 @MiloATH @marigerr and others