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.

  <div class="container-fluid">
    <div id="currentLocation" class="currentLocation">Loading...</div>
    <div id="weatherIcons" class="weatherIcons">
    <div id="currentWeather" class="currentWeather"></div>
    <div class="currentTemperature"><span id="currentTemperature">&deg;C</span></div>
              body {
  background-color: #007CBD;
  color: #faebd7;
  text-align: center;
  font-family: 'Raleway', sans-serif;
  margin: 50px 0 auto;
  letter-spacing: 3px;
  font-weight: 300;

.container-fluid {
  display: inline-block;

.currentLocation {
  font-size: 300%;
  margin: 25px auto;

.weatherIcons {
  font-size: 120px;
  margin: 0 auto 40px;

.currentWeather {
  margin: 0 auto 25px;
  font-size: 200%;

.currentTemperature {
  font-size: 60px;
  margin: 0 auto 15px;
  display: inline-block;
  cursor: pointer;
  color: #fc3;

              $(document).ready(function() {
  // Check whether browser supports Geolocation API or not
  if (navigator.geolocation) {
    // Supported
  } else {
    // Not supported
    alert("Oops! This browser does not support HTML Geolocation.");

  function getPosition(position) {
    let lat = position.coords.latitude;
    let lon = position.coords.longitude;

    //Call to weather API
    const API_KEY = "e188b6a2a5b9a44694ce486159c34452";
    let url =
      "https://api.openweathermap.org/data/2.5/weather?units=metric&lat=" +
      lat +
      "&lon=" +
      lon +
      "&APPID=" +
    $.getJSON(url, function(weatherData) {
      let currentLocation = weatherData.name;
      let currentTemperature = Math.floor(weatherData.main.temp);
      let currentWeather = weatherData.weather[0].description;
      let weatherIcon = weatherData.weather[0].icon;
      let temp_max = Math.floor(weatherData.main.temp_max);
      let temp_min = Math.floor(weatherData.main.temp_min);
      $("#currentTemperature").html(currentTemperature + "°C");

      //Prepend icons into our icon class
      //We want to prepend our ID with an icon depending on the weather

      function getIcon(weatherIcon) {
        let iconsMap = {
          "01d": "wi wi-day-sunny",
          "02d": "wi wi-day-cloudy",
          "03d": "wi wi-day-sunny-overcast",
          "04d": "wi wi-cloud",
          "09d": "wi wi-rain",
          "10d": "wi wi-day-showers",
          "11d": "wi wi-day-thunderstorm",
          "13d": "wi wi-day-snow",
          "50d": "wi wi-day-fog",

          "01n": "wi wi-night-clear",
          "02n": "wi wi-night-partly-cloudy",
          "03n": "wi wi-cloudy",
          "04n": "wi wi-night-cloudy",
          "09n": "wi wi-night-alt-showers",
          "10n": "wi wi-night-rain",
          "13n": "wi wi-night-snow",
          "50n": "wi wi-night-fog"
        return iconsMap[weatherIcon];

      //Convert between C and F
      function getTemperature () {
      let celsius = currentTemperature;
      let fahrenheit = Math.floor(celsius * 1.8 + 32);
      let showF = false;

      $("#currentTemperature").click(function() {
        showF = !showF;
        if (showF) {
          $("#currentTemperature").html(fahrenheit + "°F");
        } else {
          $("#currentTemperature").html(celsius + "°C");

    function setColors() {
    let colors = {
              morning: "#44BFFF",
              noon: "#007CBD",
              night: "#19120A"
    let currentTime = new Date().getHours();
            if (currentTime >= 6 && currentTime <= 12) {
              $("body").css("background-color", colors.morning);
              else if (currentTime >= 12 && currentTime <= 18) {
              $("body").css("background-color", colors.noon);
                else {
              $("body").css("background-color", colors.night);
    }); //getJSON
  } //getPosition
}); //documentReady

🕑 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.