css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Weather App</title>
<link rel="stylesheet" href="style.css">
<!-- bootstrap -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="text/javascript" href="app.js">

 <div class="container">
  <nav class="navbar navbar-inverse navbar-fixed-top">
   <div class="navbar-header">
    <a class="navbar-brand" href="#">Weather App</a>
   <!-- navbar-header -->

  <div class="spacer"></div>
  <div class="block">
   <h1 class="text-center"><span id="currentTemp"></span></h1>
   <h1 class="text-center"><span id="currentWeather"></span></h1>
   <span><a href="#" id="toggle">Celsius/Fahrenheit</a></span><br><br>

   <!-- weather infro -->
   You're in: <span id="country"></span><br> City of: <span id="city"></span><br> Latitude: <span id="latitude"></span><br> Longitude: <span id="longitude"></span><br>
  <div class="spacer"></div>
 <!-- container --><br>
 <footer id="footer">
  <ul class="nav navbar-nav">
   <p>&copy All rights reserved to
    <a href="https://www.freecodecamp.com/charlesmarlow" target="_blank">
			Charles Marlow</a></p>

 <!-- app's javascript -->
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
 <script type="text/javascript" src="app.js"></script>
 <!-- jQuery -->


              .block {
	background-color: black;
	opacity: 0.75;
	color: white;
	padding: 50px;
	width: 50%;
	margin-right: auto;
	margin-left: auto;
	border-radius: 15px;
	font-size: 1.5em;
	padding-bottom: 3%;

.spacer {
	padding: 5%;

body {
	background: no-repeat center center fixed;
	-webkit-background-size: cover;
	-mox-background-size: cover;
	background-size: cover;

#footer {
	background-color: black;
	opacity: 0.75;
	color: white;
	padding: 20px 0px 0px 120px;
	width: 35%;
	margin-right: auto;
	margin-left: auto;
	border-radius: 15px;
	font-size: 24px;
	padding-bottom: 3%;

#toggle {
	margin: 150px;
	font-size: 20px;

              /* This app fetches a user's geolocation using latitude/longitude
 data and delivers local current weather in return, using the 
 www.openweathermap.com API */

	var C = false;
	var apiData;
	var backgroundImg = [
		// 299
		"Thunderstorm- https://dreamlandia.com/images/T/thunderstorm.jpg", 
		// 499 drizzle
		// 599 rain
		// 699 snow
		// 799 fog
		// 800 clear
		// >800 cloudy
		// appid=de3cf8ea4a51adc3c85e1727f930042c 
	// display temps in Fahrenheit/Celsius
	function displayTemp(F, C){
		if (C) return Math.round((F - 32) * (5/9)) + "&deg; C";
		return Math.round(F) + "&deg; F";
	// render data
	function render(data, C){
		var currentWeather = data.weather[0].description;
		var currentTemp = displayTemp(data.main.temp, C);
		var icon = data.weather[0].icon;
		var iconSrc = "https://openweathermap.org/img/w" + icon + ".png";
		$("#currentTemp").prepend("<img src=" +iconSrc + ">");
	// get user location using latitude/longitude
	$.getJSON("https://freegeoip.net/json/", function(location){
		//console.log(location); success
		$.getJSON("https://api.openweathermap.org/data/2.5/weather?lat=" + location.latitude + "&lon=" + location.longitude + "&units=imperial&APPID=81596f0998590acf3d21e58d3e7b4215", function(data){
			apiData = data;
			//console.log(apiData); success
			render(apiData, C);
				C = !C;
				render(apiData, C);
			var id = data.weather[0].id,
					bgId = [299, 499, 599, 699, 799, 800];
			bgIndex = bgId.sort().indexOf(id);
			//console.log(bgId); success
			$("body").css('background-image', 'url(' + backgroundImg[bgIndex] + ')');
🕑 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.
Loading ..................