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.

            
              <div class="container">
  <div class="row">
    <div class="col-md-8 mx-auto">
      <h1 class="text-center mt-4"><i class="fas fa-bolt"></i><i class="fas fa-cloud"></i><i class="fas fa-sun"></i></h1>
      
      <!-- Name of city/country -->
      <h1 class="text-center">Weather for: <span id="name">Loading...</span></h1>
      <hr class="style-two">
      
      <!-- Tell the current weather and what to bring -->
      <p class="text-center">It seems to be <span id="weather" class="bold">Loading...</span>at your location. You might want to bring <span id="itemForWeather" class="bold">Loading...</span></p>

      <!-- Headings for Temp/Humid/Wind -->
      <div class="flex">
        <div class="heading">
          <h3><i class="fas fa-thermometer-half fa-xs"></i> Temp</h3>
        </div>
        <div class="heading">
          <h3><i class="fas fa-tint fa-xs"></i> Humid</h3>
        </div>
        <div class="heading">
          <h3><i class="fab fa-cloudversify fa-xs"></i> Wind</h3>
        </div>
      </div>
      
      <!-- Boxes with numbers for Temp/Humid/Wind -->
      <div class="flex">
        <div class="box">
          <p id="temp">Loading...</p>
        </div>
        <div class="box">
          <p id="humidity">Loading...</p>
        </div>
        <div class="box">
          <p id="wind">Loading...</p>
        </div>
      </div>
      
    </div>
  </div>
</div>
            
          
!
            
              body {
  font-family: 'Jua', sans-serif;
  background: #212121;
  color: #fff;
}

/* hr */
hr.style-two {
  border: 0;
  height: 2px;
  background-image: linear-gradient(to right, rgba(256, 256, 256, 0), rgba(256, 256, 256, 0.75), rgba(256, 256, 256, 0));
}

/* Headings for boxes */
.heading {
  width: 30%;
  height: 30px;
  margin: 5px 5px;
  float: left;
  text-align: center;
}

/* Box */
.box {
  width: 30%;
  height: 50px;
  margin: 5px 5px;
  padding-top: 5px;
  float: left;
  background: #fff;
  color: #000;
  font-size: 20px;
  border: 5px solid black;
  border-radius: 25px;
  text-align: center;
}

/* The div for the boxes*/
.flex {
  display: flex;                  /* establish flex container */
  flex-direction: row;            /* default value; can be omitted */
  flex-wrap: nowrap;              /* default value; can be omitted */
  justify-content: space-between; /* switched from default (flex-start, see below) */
}

/* Make text bold and bigger */
.bold {
  font-weight: bold;
  font-size: 20px;
  text-decoration: underline;
}

            
          
!
            
              // Vars for lat and long (position)
let lat = '';
let lon = '';

// Api address
let api;

// Celcius / Fahrenheit
let isFahrenheit = false;

// Var to store XML responseText in
let response;

// Get variables
const icon = document.getElementById('icon');
const name = document.getElementById('name');
const weather = document.getElementById('weather');
const itemForWeather = document.getElementById('itemForWeather');
const temp = document.getElementById('temp');
const humidity = document.getElementById('humidity');
const wind = document.getElementById('wind');
const celOrFah = document.getElementById('celOrFah');

// Invoke UI
UI();

function UI(){
  // Find user location
  if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    lat = position.coords.latitude;
    lon = position.coords.longitude;
    api = 'https://fcc-weather-api.glitch.me/api/current?lat=' + lat + '&lon=' + lon;
    
    let XHR = new XMLHttpRequest();
    
    XHR.open('GET', api);
    XHR.onload = function(){
      if(XHR.status == 200){
        response = JSON.parse(XHR.responseText);
        name.innerHTML = response.name + ', ' + response.sys.country;
        weather.innerHTML = response.weather[0].main + '<img src="' + response.weather[0].icon + '">';
        itemForWeather.innerHTML = findItemForWeather(response.weather[0].main);
        // Temp
        temp.innerHTML = Math.round(response.main.temp) + '°<a href="#" onclick="change()">C</a>'; 
        // Humidity
        humidity.innerHTML = response.main.humidity + ' RH';
        //Wind
        wind.innerHTML = response.wind.speed + ' M/S';
      }
    }
    XHR.onerror = function() {
      console.log('error');
    }
    XHR.send(); 
  });
  } else {
    console.log("Geolocation is not supported by this browser.");
  }
}

function change() {
  isFahrenheit = !isFahrenheit;
  if(isFahrenheit){
    temp.innerHTML = Math.round((response.main.temp * 9/5) + 32) + '°<a href="#" onclick="change()">F</a>';
  } else {
    temp.innerHTML = Math.round(response.main.temp) + '°<a href="#" onclick="change()"">C</a>';
  }
}

// Find qoute for weather
function findItemForWeather(weather){
  let theWeather = weather.toLowerCase();
  switch(theWeather) {
    case 'clear':
        return 'a pair of sunglasses!';
        break;
    case 'rain':
        return 'an umbrella!';
        break;
    case 'clouds':
        return 'a positive attitude with you!';
        break;
    case 'snow':
        return 'a winter jacket!';
        break;
    case 'thunderstorm':
        return 'a umbrella, but you should really wait out the storm!';
        break;
    default:
        return 'a smile with you!';
  }
}
            
          
!
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.

Console