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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 href="https://fonts.googleapis.com/css?family=Abril+Fatface" rel="stylesheet">

<link href="https://fonts.googleapis.com/css?family=Poppins:500" rel="stylesheet">

<!-- imported assets above this line-->

<body>
  <!--
Set the background img as class and switch them with the js classList
-->
  <div class="header">
  <h1>Local Weather App</h1>
  </div>
    
  <div class="container">
    <div class="location">
  <h3>Country: <span class="country"></span></h3>
  <h3>City: <span class="city"></span></h3>
    </div>
  
  <div class="information">
<p>Forecast: <span class="weather"></span><img class="icon"></img></p>
  
<p>Temperature: <span class="temp"></span> <span class="unit"></span></p>
    
<p>Wind Speed: <span class="wind"></span> knots</p>
</div>
  
  <div>
    <button class="btn btn-success">C° to F°</button>
  </div>
  </div>

<p class="trial"></p>
  
</body>
              
            
!

CSS

              
                body {
  /*background-color: #d5d2d8;*/
background-color: #fff; 
background-image: 
linear-gradient(90deg, transparent 79px, #abced4 79px, #abced4 81px, transparent 81px),
linear-gradient(#eee .1em, transparent .1em);
background-size: 100% 1.2em;
}

h1 {
  margin: 0;
  padding: 17px 0;
  text-align:center;
  text-transform: uppercase;
  color: #272828;
  background-color: #fcec37;
  box-shadow: 3px 2px 15px #272728;
  font-family: 'Abril Fatface', cursive;
  letter-spacing: 0.4em;
  font-weight: 700;
}

.information {
  font-size: 20px;
  font-family: "helvetica";
  color: black;
}

.container {
  margin-left: 38%;
  margin-top: 2%
}

.location{
  font-family: 'Poppins', sans-serif;
  font-weight: 600;
  color: black;
}

.information {
  margin-top: 32px;
  font-family: 'Poppins', sans-serif;
}

.btn {
  margin: 25px 7%;
}
              
            
!

JS

              
                var temperature = document.querySelector(".btn");
var units = document.querySelector(".unit");

//make btn toggle between C° to F°

temperature.addEventListener("click", function(){
if(temperature.innerHTML === "C° to F°"){
    temperature.textContent = "F° to C°"    
  } else {
    temperature.textContent = "C° to F°"
  }
});

//toggle temperature measurement units

temperature.addEventListener("click",       function(){

      if(temperature.innerHTML === "C° to F°"){
   units.textContent = "C°"    
   } else {
    units.textContent = "F°"
   }
});

units.textContent = "C°"

//obtain user's geolocation

   if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(function(position) {
            var pos = {
              lat: position.coords.latitude,
              lng: position.coords.longitude
            };
            var latitude = pos.lat;
            var longitude = pos.lng;            
         

//receive data from Weather JSON API

$(document).ready(function() {
  $.getJSON('https://fcc-weather-api.glitch.me/api/current?lat='+ latitude + '&lon='+ longitude, function(json){

var newTemp = $(".temp");
var units = $(".unit");
var measurement = units[0].innerHTML;
    
//render the JSON response into HTML
    
//country information
    
var country = json.sys.country;
var coun = $(".country");
    
coun.text(country);
    
//city information
    
var city = json.name;
var cit = $(".city");
     
cit.text(city);

//weather report
    
$(".weather").html(JSON.stringify(json.weather[0].description));
    
//wind speed in nautical miles
        $(".wind").html(JSON.stringify(json.wind.speed));

//toggle temperature C° into F° and vice versa

var celsius = json.main.temp;
var fahr = celsius * 9 / 5 + 32;
    
newTemp.text(celsius);

$(temperature).click(function (){
  if(units[0].innerHTML === "C°") { newTemp.text(celsius)
} else {
newTemp.text(fahr)  
}
})
    
//icon properties depending on weather

var image = json.weather[0].icon;
    
$(".icon").attr("src", image);
    
});
});
            
}
)};
              
            
!
999px

Console