css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <h1 class="header">Weather</h1><br>

<h2 class="location">We cannot find your location!</h2><br>

<button onclick ="changeTemp(temperature);" class="temperature" id="temperature" value="button text">60°F</button>

<br><br>

<img id="img" src="" class="weatherPic"><br><br></img>
<h2 class="conditions"></h2>

<h2 class="sunrise"></h2>
<h2 class="sunset"></h2>

<h3 class="footer"><a href="/">© Nick Katchur</a></h3>
            
          
!
            
              .header {
  text-align: center;
}

body {
  font-family: 'Coiny', cursive;
  color: white;
  background-color: black;
  text-align: center;
}


/*Footer name and link styling*/

.footer {
  text-decoration: none;
  color: white;
  background-color: black;
  margin-right: auto;
  bottom: 0;
}


/*To remove blue coloring and hover effect of link*/

a:link,
a:hover,
a:active,
a:visited {
  color: white;
  text-decoration: none;
}

/*Temperature text and button formating*/

.temperature {
  font-size: 200%;
  text-decoration: none;
  background-color: black;
  border: none;
}
            
          
!
            
              /*Creating temps array for later use with retrieved temperatures*/
temps = [60, 15.6, 288.7];
/*Assigning fareinheit to corresponding temperature*/
var temperature = temps[0] + "°F";

/*Switching temperature between F, C, and K*/
function changeTemp(temperature) {
  if (document.getElementById("temperature").textContent.slice(-1) == "F") {
    $(".temperature").text(temps[1] + "°C");
  } else if (document.getElementById("temperature").textContent.slice(-1) == "C") {
    $(".temperature").text(temps[2] + "K");
  } else if (document.getElementById("temperature").textContent.slice(-1) == "K") {
    $(".temperature").text(temps[0] + "°F");
  }
}

$(document).ready(function() {

  /*Sending GET request to find out current location*/
  $.getJSON("http://ip-api.com/json", function(val) {
    var apiLocation = val.zip + "," + val.countryCode;
    /*Displaying current location*/
    $(".location").text(val.city);
    if (val.city === undefined) {
      var geo_options = {enableHighAccuracy: true};
      navigator.geolocation.watchPosition(geo_options);
      var latitude = position.coords.latitude;
      var longitude = position.coords.longitude;
      var locationURL = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + String(latitude) + "," + String(longitude) + "&key=AIzaSyCWc4g8rzR8G71wu1mrDIDEgGomqnOldHM";
      $.getJSON(locationURL, function(local) {
        $(".location").text(local.results.address_components[3].long_name);
        apiLocation = local.results.address_components[6].long_name + "," + local.results.address_components[7].long_name;
      });
    }

    /*Getting location and assigning to openweather url*/
    apiUrl = "http://api.openweathermap.org/data/2.5/weather?zip=" + apiLocation + "&appid=569f4824cb1a2a5e07f330acd20cfd48";

    /*Sending GET request for weather at the zipcode location*/
    $.getJSON(apiUrl, function(value) {

      /*Assigning retrieved temperatures to temps array for later use*/
      temps[0] = Math.round((value.main.temp - 273) * 9 / 5) + 32;
      temps[1] = Math.round(value.main.temp - 273);
      temps[2] = Math.round(value.main.temp);

      /*Retreiving the OpenWeatherMap date from the jQuery request and converting it into standard long format.*/
      var sunriseDate = new Date(value.sys.sunrise * 1000);
      /*Getting the hours from the date value*/
      var sunriseHour = sunriseDate.getHours();
      /*Getting the minutes from the date value */
      var sunriseMinutes = sunriseDate.getMinutes();
      /*Creating the full correct formatted time for sunrise in order to be used later*/
      var sunrise = String(sunriseHour) + ":" + String(sunriseMinutes) + " AM";
      /*Displaying the sunrise time*/
      $(".sunrise").text("Sunrise: " + sunrise);

      /*Getting and displaying the sunset time*/
      var sunsetDate = new Date(value.sys.sunset * 1000);
      var sunsetHour = sunsetDate.getHours() - 12;
      var sunsetMinutes = sunsetDate.getMinutes();
      var sunset = String(sunsetHour) + ":" + String(sunsetMinutes) + " PM";
      $(".sunset").text("Sunset: " + sunset);

      /*Getting and displaying the weather coditions icon*/
      var icon = value.weather[0].icon;
      var iconUrl = "http://openweathermap.org/img/w/" + icon + ".png";
      document.getElementById("img").src = iconUrl;

      /*Getting and displaying the weather conditions*/
      var conditions = value.weather[0].main;
      $(".conditions").text(conditions);

      /*Displaying temperature*/
      $(".temperature").text(temps[0] + "°F");
    });
  });
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console