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.

            
              <!--Make page mobile responsive-->
<div class="container-fluid">
    
    <!--Create a header panel with centered text-->
    <div class="white-panel">
      <h1>Current Local Weather</h1>
    </div>
    
    <!--Create a panel to display weather information-->
    <div class ="white-panel text-center">
      <!--Create a division to show user's nearest city-->
      <div class="city"></div>
      <!--Create a division to show a symbol representing the weather in the user's current location-->
      <div id="icon">
        <img src="#">
      </div>
      <!--Create a division to show a description of the weather in the user's current location-->
      <div class="weather"></div>
      <!--Create a division to show the temperature in teh user's current location-->
      <div class="temp"></div>
      <!--Create a button to toggle between Celsius and Fahrenheit-->
      <button type="button" class="btn btn-default" id="units" title="Metric/Imperial">
        Metric/Imperial
      </button>
    </div>   
</div>
            
          
!
            
              body {
  background-color: #000;
  padding-top: 6rem;
  font-family: Impact;
}

.container-fluid {
  display: flex;
  flex-direction: column;
}

.white-panel {
  background-color: #FFF;
  padding: 3rem;
  border-radius: 1rem;
  margin: 2rem auto;
  text-align: center;
}

h1 {
  margin: 0;
  display: inline;
}

.city {
  font-size: 250%;
}

.weather {
  font-size: 170%;
}

.temp {
  font-size: 170%;
}
            
          
!
            
              $(document).ready(function() {
  //Make Fahreneheit the default unit
  let fahrenheit = true;
  
  //Set up global temperature variables so they are accessible to the conversion button
  let celsiusTemp = 0;
  let fahrenheitTemp = 0;
          
  //Get location and weather information  
  $.getJSON("https://api.ipinfodb.com/v3/ip-city/?key=d25c9fbb13ea0e29aa829287bc5568f17586440a109385f08ed4c22b61bb6d12&format=json", response => {
    //Retrieve name of city from API response
    const city = response.cityName;
    //Split city name into an array
    const splitArray = city.split("");
    //Remove spaces from array
    const filteredArray = splitArray.filter(function(val) {
      return val != " ";
    });
    //Rejoin characters
    const noSpaces = filteredArray.join("");
    //Turn array back into a string
    const cityString = noSpaces.toString();
    
    //Setup URL for weather API
    const url = "https://api.openweathermap.org/data/2.5/weather?q=" + cityString + "&appid=02282750d865580915ab2d3c4dfc05a3";
    //Send request to weather API
    $.getJSON(url, data => {
      //Assign weather data to variables
      const weatherDescription = data.weather[0].description;
      const kelvinTemp = data.main.temp;
      //Convert Kelvin temperature to Celsius
      celsiusTemp = Math.round(kelvinTemp-273);
      //Convert Celsius temperature to Fahrenheit
      fahrenheitTemp = Math.round((celsiusTemp)*(9/5)+32);
      const icon = data.weather[0].icon;
      const iconUrl = "http://openweathermap.org/img/w/" + icon + ".png";
      
      //Display location and weather data
      $(".city").text(city);
      $(".weather").text(weatherDescription);
      $(".temp").text(fahrenheitTemp + "\u00b0 F" );
      $("#icon img").attr("src", iconUrl);
    });
  });
  
  //Set up button to toggle between Celsius and Fahrenheit
  $("#units").on("click", function() {
    if (fahrenheit === true) {
      $(".temp").text(celsiusTemp + "\u00b0 C");
      fahrenheit = false;
    }
    else {
      $(".temp").text(fahrenheitTemp + "\u00b0 F");
      fahrenheit = true;
    }
  });
  
 });
            
          
!
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