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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <html >
  <head>
    <meta charset="UTF-8">
    <title>Weather App</title>

    <link href="https://fonts.googleapis.com/css?family=Bellefair" rel="stylesheet">

  </head>

  <body>
    <div class = "container main">

      <div class = "row">

        <div class="jumbotron col-lg-12 col-md-12 col-sm-12" id="header">

          <h1>
          Weather App
          </h1>

        </div>

      </div>


      <div class = "jumbotron container">
        <div class = "table-responsive">
          <h4>
            <div class = "col-lg-4 col-md-4 col-sm-4 data" id = "date">Date</div>
            <em><div class = "col-lg-4 col-md-4 col-sm-4 data" id = "temp">Temp</div></em>
            </br>
            </br>
            <div class = "col-lg-6 col-md-6 col-sm-6 data" id = "weather">Weather</div>
            </br>
            <div class = "col-lg-6 col-md-6 col-sm-6 data" id = "humidity">Humidity</div>
            </br>
            <div class = "col-lg-6 col-md-6 col-sm-6 data" id = "precip">Precip</div>
          </h4>
        </div>
        <div class = "col-lg-8 col-md-8 col-sm-8">

          <button class = "btn btn-primary" id = "celcius">C</button>

          <button class = "btn btn-success" id = "fahr">F</button>

        </div>

      </div>


      <div class = "jumbotron container">

        <h1 class= "col-lg-9 col-md-9 col-sm-9">Next 6 Hours:</h1>

        <button class = "btn btn-warning col-lg-3 col-md-3 col-sm-3 " id = "hourly">H</button>

        <div class = "col-lg-8 col-md-8 col-sm-8">

          <button class = "btn btn-primary" id = "celciusHr">°C</button>

          <button class = "btn btn-success" id = "fahrHr">°F</button>

        </div>

        <div class = "row col-lg-12 col-md-12 col-sm-12" id = "hr">

	<div class = "table-responsive col-lg-2 col-md-2 col-sm-2">
		<strong> <div class = "hour1"></div> </strong>
		<div class = "temp1"></div>
		<div class = "summary1"></div>
		</br>
	</div>

	<div class = "table-responsive col-lg-2 col-md-2 col-sm-2">
		<strong> <div class = "hour2"></div> </strong>
		<div class = "temp2"></div>
		<div class = "summary2"></div>
		</br>
	</div>

	<div class = "table-responsive col-lg-2 col-md-2 col-sm-2">
		<strong> <div class = "hour3"></div> </strong>
		<div class = "temp3"></div>
		<div class = "summary3"></div>
		</br>
	</div>

	<div class = "table-responsive col-lg-2 col-md-2 col-sm-2">
		<strong> <div class = "hour4"></div> </strong>
		<div class = "temp4"></div>
		<div class = "summary4"></div>
		</br>
	</div>

	<div class = "table-responsive col-lg-2 col-md-2 col-sm-2">
		<strong> <div class = "hour5"></div> </strong>
		<div class = "temp5"></div>
		<div class = "summary5"></div>
		</br>
	</div>

	<div class = "table-responsive col-lg-2 col-md-2 col-sm-2">
		<strong> <div class = "hour6"></div> </strong>
		<div class = "temp6"></div>
		<div class = "summary6"></div>
		</br>
	</div>
        </div>
      </div>

    </div>

    <div class = "container">
      <footer class="white-text black text-center full">
        Written and &ltCoded&gt by Mohammad Nadeem<br/>

        <a href="https://github.com/mnadev"><i class="fa fa-github-square fa-2x"></i></a>

        <a href="https://www.linkedin.com/in/mohammed-nadeem-a01714126"><i class="fa fa-linkedin fa-2x"></i></a>
      </footer>
    </div>

  </body>
</html>

              
            
!

CSS

              
                body {
	background-color: black;
	font-family: "Bellefair", "serif";
}
#data {
	height: 100px;
	padding: inherit;
	margin:auto;
	font-size: 50px;
}
footer{
  color: white;
}

              
            
!

JS

              
                $(document).ready( function() {
	$("#hr").hide();

	var iploc = "https://freegeoip.net/json/"; //get location from ip address
	$.getJSON(iploc, function(json) {
		var coords = json.latitude + "," + json.longitude; //get coordinates
		console.log(coords);
		var url = "https://api.darksky.net/forecast/3ea43a2695b2c51b6cdea9820fc7aca2" + "/" + coords + '?callback=?'; //dark sky url for api call
		console.log(url)
		$.getJSON(url, function(jsonWeather) { //getting weather data in JSON format from Dark Sky API
			var weather = jsonWeather.currently.summary; //get weather summary
			var temp = jsonWeather.currently.temperature.toFixed(1); //get current temp
			var precipChance = jsonWeather.currently.precipProbability * 100; //precipiation chance in percent
			var humidity = jsonWeather.currently.humidity * 100; //humidity
			var hourlySummary = jsonWeather.hourly.summary; //weather summary i.e "partly cloudy with a chance of rain, etc."
			console.log(temp);
			console.log(weather);
			var dateObj = new Date(); //create new date object
			var monthArr = ["January", "February" , "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
			var currHour = dateObj.getHours() % 12; //current hour
			var date = currHour + ":" + dateObj.getMinutes() + ", " + monthArr[dateObj.getMonth()] + " " + dateObj.getDate(); //get hours, min, day, month
			var isFahrenheit = true; //create variable to check if temp is in fahrenheit or celcius

			var body  = document.getElementsByTagName("body")[0]; //access body element
			var mainDiv = document.getElementById("main"); // get div of id main

			$("#temp").text(temp + " °F");

			$('#date').text(date);

			$('#weather').html("The weather is " + weather);

			$("#humidity").text(humidity.toFixed(1) + "% humidity");

			$("#precip").text(precipChance.toFixed(1) + "% precipitation chance");

			$("#celcius").text("°C");

			$("#fahr").text("°F");

			$("#celcius").click(function(event) {
				if(isFahrenheit) { //check if temp is in degrees fahrenheit
					temp = (temp - 32) * (5/9); //convert function to celcius from fahrenheit
					temp = temp.toFixed(1);
					$("#temp").text(temp + "°C");
					isFahrenheit = false;
				}
			});

			$("#fahr").click(function(event) {
				if(!isFahrenheit) { //check if temp is in degrees fahrenheit
					temp = (temp * 9/5) + 32; //convert function to celcius from fahrenheit
					temp = temp.toFixed(1);
					$("#temp").text(temp + "°F");
					isFahrenheit = true;
				}
			});

			$("#hourly").text("Show next 6 hours:");

			$("#hourly").click(function(event) {
				var hourlyData = jsonWeather.hourly.data;
				var hourlyTemps = new Array(6); //array storing temperature each hour
				var hourlySummary = new Array(6);

				for(var i = 1; i < 7; i++) { //iterate through each hour, getting data
					hourlyTemps[i] = hourlyData[i].temperature.toFixed(1);
					hourlySummary[i] = hourlyData[i].summary;
					var classHr = ".hour" + i; //html classes for each hour
					var classTemp = ".temp" + i;
					var classSumm = ".summary" + i;

					var hour = (currHour + i) % 12;
					if(hour == 0) {
						hour = 12;
					}
					$(classHr).text(hour + " o'clock");

					$(classTemp).text(hourlyTemps[i] + " °F");
					$(classSumm).text(hourlySummary[i]);
				}

				$("#hr").show();
				var isFahrHr = true

				$("#celciusHr").click(function(event) {
					if(isFahrenheit) { //check if temp is in degrees fahrenheit
						for(i = 1; i < 7; i++) {
							hourlyTemps[i] = (hourlyTemps[i] - 32) * 5/9; //convert function to celcius from fahrenheit
							hourlyTemps[i] = hourlyTemps[i].toFixed(1);
							var classTempHr = ".temp" + i;

							$(classTempHr).text(hourlyTemps[i] + "°C");
							isFahrenheit = false;
						}
					}
				});

				$("#fahrHr").click(function(event) {
					if(!isFahrenheit) { //check if temp is in degrees fahrenheit

						for(i = 1; i < 7; i++) {
							hourlyTemps[i] = (hourlyTemps[i] * 9/5) + 32; //convert function to celcius from fahrenheit
							hourlyTemps[i] = hourlyTemps[i].toFixed(1);
							var classTempHr = ".temp" + i;

							$(classTempHr).text(hourlyTemps[i] + "°F");
							isFahrenheit = true;
						}
					}
				});
			});

		});
	});
});

              
            
!
999px

Console