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>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>
            
          
!
            
              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%;
}
            
          
!
            
              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
🕑 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.

Console