cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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 lang="en">
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->

	<title>Show the Local Weather</title>

	<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
	<link href="css/style.css" rel="stylesheet">

	<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>


<div id="bg">
	<div class="flexbox-container" id="container">
		<div class="flexbox-container" id="circle">
			<div id="weather">
				<p id="temp"></p>
				<p id="condition"></p>
				<p id="location"></p>

<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="js/index.js"></script>

              /********** GLOBAL STYLES **********/

/* Testing purposes */
* {
	border: 0px solid red;

html, body {
	height: 100%;
	margin: 0;

body {
	background-color: lightblue;
	-webkit-font-smoothing: antialiased;
	text-rendering: optimizelegibility; 

#bg {
    background-position:50% 50%;
    background-size: cover;
    -webkit-background-size: cover;
 	-moz-background-size: cover;
	-o-background-size: cover;

a, a:visited {
	color: gray;
	text-decoration: none;

a:hover {
    color: darkgray;

/********** WEATHER SECTION **********/

.flexbox-container {
	display: flex;
	display: -ms-flexbox;
	display: -webkit-flex;

	justify-content: center;
	align-items: center;
	-ms-flex-align: center;
	-webkit-align-items: center;
	-webkit-box-align: center;

#container {
	height: 100%;

#circle {
	background: white;
	text-align: center;
	width: 300px;
	height: 300px;
	padding: 20px;
	border: 2px solid black;
	border-radius: 50%;
	transition:background 1s; 
	opacity: 0.5;

#circle:hover {
	opacity: 1;

#weather {
	font-family: 'Open Sans', sans-serif;
	font-size: 30px;

#location {
	font-size: 17px;

p, h1 {
	margin: 5px;

h1 {
	font-size: 110px;
              var Fahrenheit = 0;
var Celsius = 0;

$( document ).ready(function() {

	// Query the IPInfo API with the current user's IP address to display their location
    $.get("//ipinfo.io", function(location) {
    	// Display user's location
  		document.getElementById("location").innerHTML = location.city + ", " + location.region;

  		// Split response's latitude and longitude into an array.
  		location.loc = location.loc.split(',');

  		// Query the OpenWeatherMap API to return weather data based on the user's location
  		$.get("//api.openweathermap.org/data/2.5/weather?lat=" + location.loc[0] + "&lon=" + location.loc[1] + "&APPID=326b00a90b7281cb02b6f79e3284673c", function(response) {
			// alert(JSON.stringify(response, null, 4)); // Shows the whole returned object nicely formatted for debugging 

			// Convert the returned temperature from Kelvin to Fahrenheit and display it. 
			Fahrenheit = Math.round((response.main.temp * (9/5)) - 459.67);
			Celsius = Math.round((Fahrenheit - 32) * (5/9));
			document.getElementById("condition").innerHTML = toTitleCase(response.weather[0].description);

			// Set the background image depending on weather condition. http://openweathermap.org/weather-conditions
			// All images free to use personal/commercial from pexels.com and pixabay.com
			var background = document.getElementById("bg");

			switch(response.weather[0].main) {
				case "Clear": 
					bg.style.backgroundImage = "url(https://raw.githubusercontent.com/WesDowney/freeCodeCamp/bc4fd93e94acc39e2a57c8af882f2e57e3bcc64d/front-end-development-certification/Intermediate-Front-End-Development-Projects/Show-the-Local-Weather/img/clear.jpg)";
				case "Clouds":
					bg.style.backgroundImage = "url(https://github.com/WesDowney/freeCodeCamp/blob/bc4fd93e94acc39e2a57c8af882f2e57e3bcc64d/front-end-development-certification/Intermediate-Front-End-Development-Projects/Show-the-Local-Weather/img/clouds.jpeg?raw=true)";
				case "Rain":
					bg.style.backgroundImage = "url(https://github.com/WesDowney/freeCodeCamp/blob/bc4fd93e94acc39e2a57c8af882f2e57e3bcc64d/front-end-development-certification/Intermediate-Front-End-Development-Projects/Show-the-Local-Weather/img/rain.jpeg?raw=true)";
				case "Drizzle":
					bg.style.backgroundImage = "url(https://github.com/WesDowney/freeCodeCamp/blob/bc4fd93e94acc39e2a57c8af882f2e57e3bcc64d/front-end-development-certification/Intermediate-Front-End-Development-Projects/Show-the-Local-Weather/img/rain.jpeg?raw=true)";
				case "Thunderstorm":
					bg.style.backgroundImage = "url(https://raw.githubusercontent.com/WesDowney/freeCodeCamp/bc4fd93e94acc39e2a57c8af882f2e57e3bcc64d/front-end-development-certification/Intermediate-Front-End-Development-Projects/Show-the-Local-Weather/img/lightning.jpg)";
				case "Snow":
					bg.style.backgroundImage = "url(https://raw.githubusercontent.com/WesDowney/freeCodeCamp/bc4fd93e94acc39e2a57c8af882f2e57e3bcc64d/front-end-development-certification/Intermediate-Front-End-Development-Projects/Show-the-Local-Weather/img/snow.jpg)";
		}, "jsonp")
	}, "jsonp")


function displayFahrenheit(){
	document.getElementById("temp").innerHTML = "<h1>" + Fahrenheit + "°<a href='#' onclick='displayCelsius()'>F</a></h1>";

function displayCelsius(){
	document.getElementById("temp").innerHTML = "<h1>" + Celsius + "°<a href='#' onclick='displayFahrenheit()'>C</a></h1>";

// http://stackoverflow.com/questions/196972/convert-string-to-proper-case-with-javascript/196991#196991
function toTitleCase(str)
    return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});

🕑 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 ..................