JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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;
}
Also see: Tab Triggers