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>
	<title>Weather data</title>
	<link rel="stylesheet" type="text/css" href="weather.css">
	<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
</head>
<body>
<h1>Local Weather Data</h1>
<div id="container">
<div>
	
	<p class="temp"><img><span id="degChange"></span>&deg;<span id="unitChange">C</span></p>
	<div id="switch">
		<label class="switch">
  <input type="checkbox">
  <span class="slider round"></span>
</label>
</div>
	</div>
<div>
	<div class="info" id="windSpeed"></div>
	<div class="info" id="weatherType"></div>
	<div class="info" id="city"></div>
</div>
<div>
	<script type="text/javascript" src="weather.js"></script>
</body>
</html>
              
            
!

CSS

              
                body{
	background:url(https://images.pexels.com/photos/66997/pexels-photo-66997.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260) center center no-repeat fixed;
	background-size:cover;
	color:white;
	padding-top:5%;
}
.info{
	float:right;
	width:30%;
	margin:1.66%;
	font-size:1.2em;
	padding-top:5%;
	text-align:center;
	border-radius:9%;
	font-weight: 800;
    text-transform: uppercase;
}
#container{
	max-width:600px;
	margin:0 auto;
}
img{
	width:5em;
	text-align:center;
}
.temp{
	max-width:27%;
	text-align:center;
	font-size:1.7em;
	margin:0 auto;
}
#switch{
	text-align:center;
	margin-top:1.2em;
}
.deg{
	font-size:1.8em;
	margin-right:5px;
	margin-left:5px;
	margin-top:-30px;
}
h1{
	text-align: center;
}

.switch {
      position: relative;
      display: inline-block;
      width: 90px;
      height: 34px;
    }

    .switch input {display:none;}

    .slider {
      position: absolute;
      cursor: pointer;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: #2ab934;
      -webkit-transition: .4s;
      transition: .4s;
       border-radius: 34px;
    }

    .slider:before {
      position: absolute;
      content: "";
      height: 26px;
      width: 25px;
      left: 4px;
      bottom: 4px;
      background-color: white;
      -webkit-transition: .4s;
      transition: .4s;
      border-radius: 50%;
    }

    input:checked + .slider {
      background-color: #2a76b9;
    }

    input:focus + .slider {
      box-shadow: 0 0 1px #2196F3;
    }

    input:checked + .slider:before {
      -webkit-transform: translateX(26px);
      -ms-transform: translateX(26px);
      transform: translateX(55px);
    }
    .slider:after
    {
     content:'C';
     color: white;
     display: block;
     position: absolute;
     transform: translate(-50%,-50%);
     top: 50%;
     left: 50%;
     font-size: 20px;
     font-family: Verdana, sans-serif;
    }

    input:checked + .slider:after
    {  
      content:'F';
    }
              
            
!

JS

              
                var unitChange = $("#unitChange");
var degChange = $("#degChange");
var lat = 0,long = 0;
var url = "";
var fah = true;
var temp = 0;
var degInFah = 0;


$(document).ready(function() {
  if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
      lat = position.coords.latitude;
      long = position.coords.longitude;
      setWeather(lat, long);
    });
  } else {
    console.log("Geolocation not supported by browser");
  }
});

//function to get the weather data 

function setWeather(lat,long) {
  url =
    "https://fcc-weather-api.glitch.me/api/current?lon=" + long + "&lat=" + lat;
  $.getJSON(url, function(response) {
    degChange.empty();
    degChange.append("<span>" + response.main.temp + "</span>");
    $("#city").append("<span>" + response.name + "</span>");
    $("img").attr("src", response.weather[0].icon);
    $("#weatherType").append(
      "<span>" + response.weather[0].description + "</span>"
    );
    $("#windSpeed").append(
      "<span>Wind Speed: " +
        Math.floor(response.wind.speed * (18 / 5)) +
        "Kmph</span>"
    );
    temp = response.main.temp;
    degInFah = Math.round(temp * (9 / 5) + 32);
  });
}

//switch for toggling units

$(".switch").on("change", function() {
  var currentTempUnit = unitChange.text();
  var newTempUnit = currentTempUnit === "C" ? "F" : "C";
  unitChange.text(newTempUnit);
  if (fah === true) {
    degChange.text(degInFah);
    fah = false;
  } else {
    degChange.text(temp);
    fah = true;
  }
});

              
            
!
999px

Console