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

              
                <h1>Weather Application</h1>
<div class="back">
<div class="weather_back">
  <br>
  <p id="city"></p>
  <p id="temp"></p>
  <p id="weather"></p>
  <p id="weather_desc"></p>
  <p > <img id="weather_icon"></p>
  <br>
  </div>
</div>
              
            
!

CSS

              
                h1{
  text-align:center;
color:brown;  background:linear-gradient(yellow,green);
  margin:0 auto;
  margin-bottom:20px;
}

body{
  background:linear-gradient(coral,yellow,red,coral);
   margin:0px;
  height:100%;
}

p{
  color:purple;
  font-family:arial;
}
div.weather_back{
  border:5px solid violet;
 background:liner-gradient(coral,purple);
  max-width:300px;
  height:250px;
  margin-right:10%;
  margin-left:10%;
  padding-left:2%;
}
              
            
!

JS

              
                var lat,long;
var temprature;
var url;
//a query selector for the temprature id dom
var Background = document.querySelector(".back"); 
var WeatherBackground = document.querySelector(".weather_back");
var City = document.querySelector("#city");
var Temprature = document.querySelector("#temp");
var Weather = document.querySelector("#weather");
var WeatherDesc = document.querySelector("#weather_desc");
var WeatherIcon = document.querySelector("#weather_icon");
var getLoc = function(position){
  //This is the latitude
    lat = position.coords.latitude;
  //This is the longitude
   long =  position.coords.longitude;
  //Url function is called
  Url(lat,long);
}
if (navigator.geolocation){
  navigator.geolocation.getCurrentPosition(getLoc);
}

//This function will wrap the weather info of my location inside a url
function Url( latitude, longitude)
{
  var url ="https://fcc-weather-api.glitch.me/api/current?lat="+latitude+"&lon="+longitude;
  //function to work with the url
  retrieve_data(url);
}

//it uses fetch method to get data from api
function retrieve_data(url)
{
  fetch(url).then(function(resolve){
    //return the json object
    return resolve.json();
    //pass the object into jsonObj function
  }).then(function(j){
    console.log(j);
    jsonObj(j);
  });
}
function jsonObj(obj){
  var jsn = obj;
  var city = jsn.name;
  var weather = jsn.weather[0].main;
  var weather_desc = jsn.weather[0].description;
  temprature = jsn.main.temp;
  var icon = jsn.weather[0].icon;
  City.textContent = "City: "+city;
  Temprature.textContent = "Temprature: "+temprature;
  Weather.textContent = "Weather: "+weather;
  WeatherDesc.textContent = "Description: "+weather_desc;
  WeatherIcon.src = icon;
}
              
            
!
999px

Console