Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body class="container">
	<div class="row">
		<div class="col-12">
			<div class="row d-flex justify-content-center">
				<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 card mt-3">
					<div class="card-body">
						<h3 class="text-center text-bold"> Weather App
							</h3>
						
						<div class="card-body text-center">
							<h4 class="city"></h4>
							<hr class="divider">
							
							<div class="text-center pb-3">
								<p class="text-temp">Today's  Temperature:</p>
								
								<p>
									<span class="temp"></span>
									<span id="tempUnit" class="tempunit"></span>
								</p>
							</div>
							
							<div class="temps row">
								<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 right-border">
									<p class="text-temp">Min.  Temperature:</p>
									<p>
									<span class="minTemp"></span>
									<span id="minUnit" class="tempunit"></span>
										</p>
								</div>

								<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
									<p class="text-temp">Max.  Temperature:</p>
									
									<span class="maxTemp"></span>
									<span id="maxUnit" class="tempunit"></span>
								</div>
							</div>
							<hr class="divider">
							
							<div class="weather-info">
								<div class="weather">
								</div>
								<i class="wi"></i>
								</div>
							</div>
						</div>
				</div>
				</div>
			</div>
		</div>
	</body>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Erica+One);

@import url(https://fonts.googleapis.com/css?family=Ribeye);

h3{
	font-family: 'Erica One', cursive;
	font-size: 50px;
	color: #81b5c0;
	text-shadow: 5px 3px #b7d78a;
}

h4,
.weather{
	font-family: 'Erica One', cursive;
	font-size: 25px;
	color: #a787bd;
	text-shadow: 5px 3px #007CB6;
}

.right-border{
	border-right: 3px dashed #dfa3a3;
}

.text-temp{
	font-weight: bold;
	margin-bottom: 0px;
	font-size: 12px;
}

.temp, 
.tempunit{
	font-family: 'Ribeye', cursive;
	font-size: 2.5em;
	color: #22758e;
	text-shadow: 3px 2px #F9C414;
}

.tempunit{
	cursor: pointer;
}

.temps .minTemp,
.temps .maxTemp,{
	font-family: 'Ribeye', cursive;
	font-size: 2.5em;
	color: #22758e;
	text-shadow: 3px 2px #F9C414;
}

.weather-info i{
	font-size: 70px;
	padding-top: 15px;
	color: #007CB6;
}

.minTemp{
	broder: 2px solid #dfa3a3;
}

.card{
	background-color: #fff;
	box-shadow: 10px 10px #4abdac, 20px 20px #fc4a14;
}

.divider {
	width: 100%;
    height: 2px;
    padding: 0;
    margin: 27px auto 25px;
    border: none;
	 background-color: #dfa3a3;
}

@media(min-width: 320px) and (max-width: 580px){
	.right-border{
		border-bottom: 3px dashed #dfa3a3;
		border-right: none;
		margin-bottom: 20px;
	}
}
              
            
!

JS

              
                var api = "https://fcc-weather-api.glitch.me/api/current?";
var lat = "43.6532";
var long = "79.3832";
var currentTempCelsius;
var currentMinTemp;
var currentMaxTemp;
var tempUnit = "C";

$(document).ready(function() {
		if (navigator.geolocation) {	navigator.geolocation.getCurrentPosition(function(position) {
			var lat = "lat=" + position.coords.latitude;
			var long = "&lon=" + position.coords.longitude;

			getWeather(lat, long);
		});
	} else {
		$(".card-body").html(
			"Unable to get current location. Please reload the page and try again."
		);
	}
	

	$("#tempUnit, #minUnit, #maxUnit").click(function() {
		var currentTempUnit = $("#tempUnit").text();
		var currentTemp = $(".temp").text();
		var currentMax = $(".maxTemp").text();
		var currentMin = $(".minTemp").text();
		var newTempUnit = currentTempUnit == "C" ? "F" : "C";
		$(".tempunit").text(newTempUnit);
if (newTempUnit == "F") {
			var fahTemp = convertFahrenheit(currentTemp);
			var fahMaxTemp = convertFahrenheit(currentMax);
			var fahMinTemp = convertFahrenheit(currentMin);
			$(".temp").text(fahTemp + " " + String.fromCharCode(176));
			$(".minTemp").text(fahMinTemp + " " + String.fromCharCode(176));
			$(".maxTemp").text(fahMaxTemp + " " + String.fromCharCode(176));
		} else {
			$(".temp").text(currentTempCelsius + " " + String.fromCharCode(176));
			$(".minTemp").text(currentMinTemp + " " + String.fromCharCode(176));
			$(".maxTemp").text(currentMaxTemp + " " + String.fromCharCode(176));
		}
	});
});

function getWeather(lat, long) {
	var jsonStr = api + lat + long;

	$.ajax({
		url: jsonStr,
		success: function(data) {
			$(".city").html(data.name + ", " + data.sys.country);

			currentTempCelsius = Math.round(data.main.temp * 10) / 10;
			currentMinTemp = Math.round(data.main.temp_min * 10) / 10;
			currentMaxTemp = Math.round(data.main.temp_max * 10) / 10;

			$(".temp").text(currentTempCelsius + " " + String.fromCharCode(176));
			$(".minTemp").html(currentMinTemp + " " + String.fromCharCode(176));
			$(".maxTemp").html(currentMaxTemp + " " + String.fromCharCode(176));
			$(".tempunit").text(tempUnit);
			$(".weather").html(data.weather[0].main);
			weatherIcons(data.weather[0].main);
		}
	});
}

function weatherIcons(weather) {
	var weather = weather.toLowerCase();

	switch (weather) {
		case "clouds":
			$("i").addClass("wi-cloudy");
			break;
		case "snow":
			$("i").addClass("wi-snow");
			break;
		case "rain":
			$("i").addClass("wi-rain");
			break;
		case "sun":
			$("i").addClass("wi-day-sunny");
			break;
		case "wind":
			$("i").addClass("wi-cloudy-gusts");
			break;
		case "thunderstom":
			$("i").addClass("wi-storm-showers");
			break;
		case "clear":
			$("i").addClass("wi-day-sunny");
			break;
			case"haze":
			$("i").addClass("wi-fog");
			break;
			case"fog":
			$("i").addClass("wi-fog");
			break;
			case"mist":
			$("i").addClass("wi-sprinkle");
			$(".weather").html("Possible Rain");
			break;
	}
}

function convertFahrenheit(temp) {
	var fahTemp = Math.round(parseInt(temp) * 9 / 5 + 32);
	
	return fahTemp;
}
              
            
!
999px

Console