Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                 <div class="app-wrap">
    <header>
      <input type="text" autocomplete="off" class="search-box" placeholder="Search for a city or country..." />
    </header>
    <main>
      <section class="location">
        <div class="city">Northampton, GB</div>
        <div class="date">Thursday 10 January 2020</div>
      </section>
      <div class="current">
        <div class="temp">15<span>°c</span></div>
        <div class="weather">Sunny</div>
        <div class="hi-low">13°c / 16°c</div>
      </div>
    </main>
  </div>
              
            
!

CSS

              
                * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  
  body {
    font-family: 'montserrat', sans-serif;
    background-image: url('https://raw.githubusercontent.com/hosseinghafouri/weather-app-real-API/main/content/images/bg.jpg');
    background-size: cover;
    background-position: top center;
  }
  
  .app-wrap {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.6));
  }
  
  header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 50px 15px 15px;
  }
  
  header input {
    width: 100%;
    max-width: 300px;
    padding: 10px 15px;
    border: none;
    outline: none;
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 16px 0px 16px 0px;
    border-bottom: 3px solid #DF8E00;
    
    color: #313131;
    font-size: 20px;
    font-weight: 300;
    transition: 0.2s ease-out;
  }
  
  header input:focus {
    background-color: rgba(255, 255, 255, 0.6);
  }
  
  main {
    flex: 1 1 100%;
    padding: 25px 25px 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  
  .location .city {
    color: #FFF;
    font-size: 32px;
    font-weight: 500;
    margin-bottom: 5px;
  }
  
  .location .date {
    color: #FFF;
    font-size: 16px;
  }
  
  .current .temp {
    color: #FFF;
    font-size: 102px;
    font-weight: 900;
    margin: 30px 0px;
    text-shadow: 2px 10px rgba(0, 0, 0, 0.6);
  }
  
  .current .temp span {
    font-weight: 500;
  }
  
  .current .weather {
    color: #FFF;
    font-size: 32px;
    font-weight: 700;
    font-style: italic;
    margin-bottom: 15px;
    text-shadow: 0px 3px rgba(0, 0, 0, 0.4);
  }
  
  .current .hi-low {
    color: #FFF;
    font-size: 24px;
    font-weight: 500;
    text-shadow: 0px 4px rgba(0, 0, 0, 0.4);
  }
              
            
!

JS

              
                let searchInput = document.querySelector(".search-box");

let apiData = {
  url: `https://api.openweathermap.org/data/2.5/weather?q=`,
  key: `9b81d3e4265e2d1a5b8b73f1591ec139`,
};

function getData(countryName) {
  fetch(`${apiData.url}${countryName}&appid=${apiData.key}`)
    .then(res => res.json())
    .then(data => {
      showData(data);
      searchInput.value = "";
    })
    .catch(res => {
      alert("There is no such country (404)");
      searchInput.value = "";
    });
};

function showData(data) {

  let  cityDiv = document.querySelector(".city"),
       dateDiv = document.querySelector(".date"),
       tempDiv = document.querySelector(".temp"),
       weatherDiv = document.querySelector(".weather"),
       highLowDiv = document.querySelector(".hi-low");


  // console.log(data.sys.country);
  cityDiv.innerHTML = `${data.name}, ${data.sys.country}`;
  dateDiv.innerHTML = showDate();
  tempDiv.innerHTML = `${Math.floor(data.main.temp - 273.15)} °c`;
  weatherDiv.innerHTML = `${data.weather[0].main}`;
  highLowDiv.innerHTML = `${Math.floor(data.main.temp_max - 273.15)} °c / ${Math.floor(data.main.temp_min - 273.15)} °c`;
};

function showDate() {
     
  let months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

  let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

  let now = new Date();

  let day = days[now.getDay()];
  let month = months[now.getMonth()];
  let year = now.getFullYear();
  let date = now.getDate();

  return `${day} ${date} ${month} ${year}`;

};

function eventSearchInput(event) {
  if (event.keyCode === 13) {
    const searchInputValue = searchInput.value;
    getData(searchInputValue);
  }
};
searchInput.addEventListener("keypress", eventSearchInput);
              
            
!
999px

Console