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.

            
              <!DOCTYPE html>
<html>
<head>
	<title>Weather App</title>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
	<link rel="stylesheet" type="text/css" href="assets/style.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/css/weather-icons.css"> 
</head>
<body id="background">
  <nav class="navbar navbar-light bg-faded">
    <form class="form-inline pull-right">
       <div class="buttons"> 
          <button class="btn selected" id="fdegrees" type="button">Fahrenheit
          </button>
          <button class="btn" id="cdegrees" type="button">Celcius
          </button>
      </div>
  </form>
  </nav>
  <div class="frame">
		<h1>Local Weather App</h1>
    <p><i id="icon" class="wi"></i></p>
    <p id="temp"></p>
		<p id="description"></p>
	</div>
	<footer>
		Made by Svetlana Shetinina 2017 using the Free Code Camp Weather API Pass-through and weather icons from <a href= 'https://erikflowers.github.io/weather-icons/'>weathericons.io</a>  For more information check out <a href= 'https://fcc-weather-api.glitch.me'>https://fcc-weather-api.glitch.me</a>
	</footer>

	<script src="assets/weatherapp.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
            
          
!
            
              body {
  background: #421C52;
}

#background {
  background-image: url(https://s2.postimg.org/943nlxzex/italy-2080072_960_720.jp);
  background-size: cover;
}

h1 {
	text-align: center;
}

p {
  text-align: center;
  height: 300%;
}

.frame {
	background: black;
	max-width: 700px;
	margin: 15% auto;
	color: white;
	padding: 3%;
	margin-bottom: 200px;
}

.btn {
  color: #ffffff;
  background-color: #000000;
}

.selected {
  background-color: #800080;
  color: #000000;
}

footer{
  color: #ffffff;
}

a[href] {
  color: #ffffff;
}

#icon {
  font-size: 250%;
  padding-top: 3%;
  padding-bottom: 1%;
}

#temp {
  font-size: 200%;
}

#description {
  font-size: 150%;
}

            
          
!
            
              $(document).ready(function(){
 
//get geolocation  
	if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      	var long = position.coords.longitude;
		    var lat = position.coords.latitude;
 
//concat get request string     
        var api ="https://fcc-weather-api.glitch.me/api/current?lat=" +lat+ '&lon=' +long;

//get data from api      
    $.getJSON(api, function(data){ 
	  var desc =
        data.weather[0].description;
	  var city = data.name;
	  var cdeg = Math.round(data.main.temp);
    var fdeg = Math.round(cdeg * (9/5) + 32);

 //App starts with Fahrenheit selected
    $('#temp').html(fdeg + " °F");    
      
    $("#description").html("The current weather in " + city + " is " + desc);


      
//Temp in Fahrenheit
$("#fdegrees").on("click", function(){
      $('#temp').html(fdeg + " °F");
});     

//Temp in Celcius      
$("#cdegrees").on("click", function(){
   $('#temp').html(cdeg + " °C");
});      
      
 //get image of icon from api                 
      //$("#icon").html("<img src='" +icon+ "'>");
      
    $("button").click(function(){
      $(".btn").toggleClass("selected");
 
    });
             
      
      if (desc.includes("clouds")) {
 $("#background").css({"background-image": "url('https://s2.postimg.org/ml9ujy3ll/overcast.jpg')", "background-size": "cover"});
 
  $("#icon").html("<i class='wi wi-cloudy'></i>");
 }
    else if (desc.includes("haze")) {
       $("#background").css({"background-image": "url('https://s2.postimg.org/ml9ujy3ll/overcast.jpg')", "background-size": "cover"});
      
      $("#icon").html("<i class='wi day-haze'></i>");
    }
 
   else if (desc.includes("rain")|| desc.includes("drizzle") || desc.includes("mist")) 
{
 $("#background").css({"background-image": "url('https://s2.postimg.org/sz3j0fiah/rain.jpg')", "background-size": "cover"});
  
  $("#icon").html("<i class='wi wi-sprinkle'></i>");
 }
         else if (desc.includes("thunderstorm") || desc.includes("hurricane")||desc.includes("tornado")) {
 $("#background").css({"background-image": "url('https://s2.postimg.org/mp89dxbbd/thunderstorm.jpg')", "background-size": "cover"});
           
    $("#icon").html("<i class='wi wi-thunderstorm'></i>");
 }
      else if (desc.includes("snow")) {
 $("#background").css({"background-image": "url('https://s2.postimg.org/o83ninx8p/snow.jpg')", "background-size": "cover"});
        
        $("#icon").html("<i class='wi wi-snow'></i>");
 }
     else if (desc.includes("hail")) {
 $("#background").css({"background-image": "url('https://s2.postimg.org/rqk8swq49/snow-1362624_340.jpg)", "background-size": "cover"});
       
       $("#icon").html("<i class='wi wi-hail'></i>");
 }
      
  else {
    $("#background").css({"background-image": "url('https://s2.postimg.org/943nlxzex/italy-2080072_960_720.jpg')", "background-size": "cover"});
    
    $("#icon").html("<i class='wi wi-day-sunny'></i>");
  }
    
    });
      
    });
        
  };
  
});
            
          
!
999px
🕑 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 ..................

Console