Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Open+Sans">

<div class="container">

  <div id="intro" class='text-center'>
    <h1>Welcome to SC's Weather App</h1>
  </div>

  <div class='row userCityRow'>
    <div id='userCity' class='col-xs-12 text-center'>
      <p><span id='currentCity'></span>
        <span id="currentTime"></span>
      </p>
      <p id='currentCityWeather'></p>
      <p id='currentCityTemp'></p>
    </div>
    <!--end userCity-->
  </div>

  <div class="col-xs-0 col-md-2 fillerRow">
  </div>

  <div class='row userSelectionRow'>
    <div class="col-xs-12 userSelection text-center">
      <div class="userSelectionInner">

        <p><input id="cityInputted" type="text" placeholder="Type a city's name" />
          <button id="getData" class="btn btn-default raised">Submit</button>
        </p>
        <p>Location: <span id="cityName"> </span>
          <span id="iconImage"></span></p>
        <p>Weather: <span id="currentWeather"></span></p>
        <p>Temperature: <span id="currentTempCel"></span>
          <span id="currentTempFar"></span></p>
        <p>Wind Speed: <span id="windSpeedKm"></span>
          <span id="windSpeedMiles"></span></p>
        <p>Humidity: <span id="humidity"></span</p>

          <p id='unitToggle'>
      <button id="farButton" class="btn btn=default">Fahrenheit</button>
      <button id="celButton" class="btn btn=default">Celsius</button>
    </p>
    
      </div>
    </div>
    </div>

  </div> <!--close row-->
  
  


  <!--BOTTOM SIDE-->


  </div>
              
            
!

CSS

              
                /*
Colors:
393939, FF5A09, F3843E, FF9900, 6E6E6E
*/

body {
  margin: 0 auto;
  padding: 0;
  color: #393939;
  font-family: 'Open Sans', sans-serif;
  font-size: 1.5em;
  background-color: #393939;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
}

#intro h1 {
  text-align: center;
  color: #F3843E;
  border-top: 1px dashed #FF9900;
  border-bottom: 1px dashed #FF9900;
  margin-bottom: 20px;
  display: inline-block;
}

input {
  color: #000;
}
#userCity {
  padding: 20px;
  border: 1px solid #FF5A09;
  color: #FF5A09;
  border-radius: 20px;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 20px;
}

#userSelectionInner {
  border: 1px solid #FF5A09;
  color: #FF5A09;
}
.userSelection {
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  border: 1px solid #FF5A09;
  border-radius: 20px;
  padding: 20px;
  color: #FFF;
}
#currentTempFar {
  display: none;
}
#windSpeedMiles {
  display: none;
}
#celButton {
  color: #000;
  background-color: #F3843E;
  display: none;
}
#farButton {
  color: #000;
  background-color: #F3843E;
}

              
            
!

JS

              
                //IP API function
var localWeather = function() {
  
  //  HERE IS THE IP-API ENDPOINT
  var geoApi = "http://ip-api.com/json";
  
  //  GETTING CERTAIN DATA FROM IP-API USING .GETJSON
  $.getJSON(geoApi, function(geoData) {
  var currentCity = geoData.city;
  var currentCountry = geoData.country;
  $("#currentCity").text('In' + ' ' + currentCity + ", " + currentCountry + ", it is: ");
  var lat = geoData.lat;
  var lon = geoData.lon;
  //console.log(lat);
  //console.log(lon);
    
    // WEATHER API DATA
    var weatherKey = '92a732418149e1fda3bccf8230242fd8';
    var weatherApi = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&units=metric&APPID=" + weatherKey;
    
    //console.log(weatherApi);
    
    $.getJSON(weatherApi, function(weatherData) {
      var humidity = weatherData.main.humidity;
      var tempCel = Math.round(weatherData.main.temp) + "°C";
      var tempFar = Math.round((weatherData.main.temp * 1.8) + 32) + "°F";
      var mainWeather = weatherData.weather[0].main;
      var descriptionWeather = weatherData.weather[0].description;
      
      $('#currentCityWeather').text(mainWeather + ", " +  descriptionWeather);
      $('#currentCityTemp').text(tempCel + ", " +  tempFar);
      

    })
});
}


// The following is the weather function
function Weather() {
  // Create function when 'getdata' (submit) button is clicked
  var cityInfo = $("#getData").click(function() {

    // Store the value the user submitted in the input text box
    var cityInputted = $("#cityInputted").val();

    //Pressing enter will work as clicking submit
    document.getElementById("cityInputted")
      .addEventListener("keyup", function(event) {
        event.preventDefault();
        if (event.keyCode == 13) {
          document.getElementById("getData").click();
        }
      });

    // Link to API, attach user's submitted city 
    $.getJSON("http://api.openweathermap.org/data/2.5/weather?q=" + cityInputted + "&appid=92a732418149e1fda3bccf8230242fd8&units=metric", function(data2) {

      // Get data from api and store it in variables
      var weatherID = data2.weather[0].id;
      console.log(weatherID);
      var tempCel = Math.round(data2.main.temp) + "°C";
      var tempFar = Math.round((data2.main.temp * 1.8) + 32) + "°F";
      var mainWeather = data2.weather[0].main;
      var descriptionWeather = data2.weather[0].description;
      var windSpeedKm = Math.round(data2.wind.speed) + ' km/hr';
      var windSpeedMiles = Math.round(data2.wind.speed * 0.62137) + ' mph';
      var humidity = data2.main.humidity;
      var icon = data2.weather[0].icon;
      var iconUrl = "http://openweathermap.org/img/w/";
      var iconImage = "http://openweathermap.org/img/w/" + icon + ".png";

      // Output the data to respective nodes
      $("#cityName").text(cityInputted);
      $('#iconImage').html("<img src=" + iconImage + ">");
      $("#currentWeather").text(mainWeather + ", " + descriptionWeather);
      $("#currentTempCel").text(tempCel);
      $("#currentTempFar").text(tempFar);
      $("#windSpeedKm").text(windSpeedKm);
      $("#windSpeedMiles").text(windSpeedMiles);
      $("#humidity").text(humidity + "%");

      //Create functionality for the Cel and Far buttons
      $('#unitToggle').on('click', function() {
        $('#farButton, #celButton, #currentTempCel, #currentTempFar, #windSpeedKm, #windSpeedMiles').toggle();
      })
/*
$('#farButton').on('click', function() {
        $("#currentTemp").text(tempFar);
        $('#windSpeed').text(windSpeedMiles);
      });

      $('#celButton').on('click', function() {
        $("#currentTemp").text(tempCel);
        $('#windSpeed').text(windSpeedKm);
      });
*/
      
      
      /*
      Change background images depending upon weather condition.
      var weatherID = data2.weather[0].id;
      Syntax : $("body").css("background-image", "url('image/setme.png')");
      */
      
      if (weatherID == 906) {
        //hail
        $("body").css("background-image", "url('https://www.google.co.uk/search?q=clouds&rlz=1C1SNNT_enCA396CA396&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiyyqHR7d_PAhXpIMAKHZANAuEQ_AUICCgB&biw=1366&bih=662#tbs=isz:l&tbm=isch&q=hail&imgrc=jh14QMQ4fWtODM%3A')");
      } else if (weatherID == 905) {
        //windy
        $(".userSelection").css("background-image", "url('http://img.wallpaperfolder.com/f/4EDA3C48C8F1/windy-day-55162.jpg')");
      } else if (weatherID == 904) {
        //hot
        $(".userSelection").css("background-image", "url('http://metrecruitmentlondon.com/wp-content/uploads/2015/07/hot-weather.jpg')");
      } else if (weatherID == 903) {
        //cold
        $(".userSelection").css("background-image", "url('http://healingfibro.com/wp-content/uploads/2014/12/cold-weather.jpg')");
      } else if (weatherID == 902) {
        // hurricane
        $(".userSelection").css("background-image", "url('http://www.ct.gov/dph/lib/dph/communications/images/hurricane.jpg')");
      } else if (weatherID == 901) {
        //tropical storm
        $(".userSelection").css("background-image", "url('https://www.japantimes.co.jp/wp-content/uploads/2015/08/f-BRI-erika-a-20150830.jpg')");
      } else if (weatherID == 900) {
        //tornado
        $(".userSelection").css("background-image", "url('https://i.ytimg.com/vi/CSn5FP1c1AQ/maxresdefault.jpg')");
      } else if ((weatherID >= 801) && (weatherID <= 804)) {
        // Rain
        console.log(weatherID);
        $(".userSelection").css("background-image", "url('https://i.stack.imgur.com/goBR5.jpg')").css('color', '#000');
      } else if (weatherID == 800) {
        // clear
        $(".userSelection").css("background-image", "url('http://img.wallpaperfolder.com/f/49A08F10D3A1/free-nature-clear-water.jpg')");
      } else if ((weatherID >= 600) && (weatherID <= 622)) {
        //snow 
        $(".userSelection").css("background-image", "url('https://speak2all.files.wordpress.com/2013/01/snow-day-stage.jpg')");
      } else if ((weatherID >= 500) && (weatherID <= 531)) {
        // Rain
        $(".userSelection").css("background-image", "url('https://i.stack.imgur.com/goBR5.jpg')");
      } else if ((weatherID >= 300) && (weatherID <= 321)) {
        //light drizzle
        $(".userSelection").css("background-image", "url('//https://i.ytimg.com/vi/LbAigABOm_E/maxresdefault.jpg')");
      } else if ((weatherID >= 200) && (weatherID <= 232)) {
        // thunderstorm
        $(".userSelection").css("background-image", "url('//http://farmersalmanac.com/wp-content/uploads/2015/06/Thunderstorm-5best.jpg')");
      }

    }); // close .getJSON weather API
  }); // close onclick function
  
  //Time
function startTime() {
  var today = new Date();
  var hours = today.getHours();
  var minutes = today.getMinutes();
  var seconds = today.getSeconds();

  if (minutes <= 9) {
    minutes = "0" + minutes;
  }
  if (seconds <= 9) {
    seconds = "0" + seconds;
  }
  if (hours >= 13) {
    hours = hours - 12;
    $("#currentTime").text(hours + ":" + minutes + ":" + seconds + " PM");
    document.getElementById("currentTime").innerHTML = hours + ":" + minutes + ":" + seconds + " PM";
  } else if (hours <= 0) {
    hours = 12;
    document.getElementById("currentTime").innerHTML = hours + ":" + minutes + ":" + seconds + " AM";
  } else {
    document.getElementById("currentTime").innerHTML = hours + ":" + minutes + ":" + seconds + " AM";
  }
  var t = setTimeout(function() {
    startTime()
  }, 1000);
}

//call startTime
startTime();

  }; //  

$(document).ready(function() {
  Weather()
  localWeather();
});
              
            
!
999px

Console