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.
<!-- Scripts Needed-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<br>
<div class="container">
<div class="row">
<div class="col-sm">
<header class="col-sm text-center">
<h1> Zalmez Weather app</h1>
</header>
</div>
</div>
</div>
<br>
<br>
<br
<div class="container">
<div class="row col-sm">
<div class="col-sm"></div>
<div class="col-sm center" id="weather-card">
<h3 class="text-center" id="temp"></h3>
<h3 class="text-center" id="city"></h3>
<h3 id="country"></h3>
<h3 class="text-center" id="weatherIcon"></h3>
<img id="desc" src=""></img>
<button type="button" class="btn btn-primary" id="swaptemp">Swap temperature unit</button>
</div>
<div class="col-sm"></div>
<div>
</div>
</div>
</div>
body{
color: white;
background-color: darkblue;
}
#weather-card{
background-color: #b9baad;
align-content: center;
}
.transparent{
background-color: transparent;
}
var api = "https://fcc-weather-api.glitch.me/api/current?";
var lat, lon;
var currentTempInCelcius;
var currentTempInFarenheit;
var tempUnit = "C";
$( document ).ready(function(){
//console.log("Ready")
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
var currentPosition = position;
var lat = currentPosition.coords.latitude;
var lon = currentPosition.coords.longitude;
getCurrentWeather(lat, lon);
});
}else{
console.log("OOOPPS! Something went wrong! Location was not shared or the browser does not support geolocation");
}
})
function getCurrentWeather(lat, lon){
//console.log("Getting current weather");
lat = Math.floor(lat);
lon = Math.floor(lon);
var weatherLink = api + "lon=" + lon + "&lat=" + lat;
//console.log(weatherLink)
$.ajax({
url: weatherLink, success: function(result){
currentTempInCelcius = result.main.temp;
currentTempInFarenheit = currentTempInCelcius * 9 / 5 + 32;
if(tempUnit == "F"){
$("temp").text(Math.floor(currentTempInFerenheit + tempUnit));
}else[]
$("#city").text(result.name + ", " + result.sys.country);
//$("#country").text("" + result.sys.country);
$("#temp").text(Math.floor(result.main.temp) + tempUnit);
//$("tempunit").text(tempUnit);
$("desc").attr("src", url(results.weather[0].icon));
//console.log("weather recived");
}
});
$ ("#swaptemp").click(function(){
if(tempUnit == "C"){
tempUnit = "F";
}else{
tempUnit = "C";
}
/*if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
var currentPosition = position;
var lat = currentPosition.coords.latitude;
var lon = currentPosition.coords.longitude;
getCurrentWeather(lat, lon);
});
}else{
console.log('OOOPPS! Something went wrong! Location was not shared or the browser does not support geolocation');
}*/
});
}
Also see: Tab Triggers