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

              
                <body>
  <center>
  <div id ="container">
    <br>
    <h1>Weather</h1>
    <p>City</p><input id="city" type="text" name="city">
    <p>State</p><select id="state">
      <option value="AL">Alabama</option>
      <option value="AK">Alaska</option>
      <option value="AZ">Arizona</option>
      <option value="AR">Arkansas</option>
      <option value="CA">California</option>
      <option value="CO">Colorado</option>
      <option value="CT">Connecticut</option>
      <option value="DE">Delaware</option>
      <option value="DC">District Of Columbia</option>
      <option value="FL">Florida</option>
      <option value="GA">Georgia</option>
      <option value="HI">Hawaii</option>
      <option value="ID">Idaho</option>
      <option value="IL">Illinois</option>
      <option value="IN">Indiana</option>
      <option value="IA">Iowa</option>
      <option value="KS">Kansas</option>
      <option value="KY">Kentucky</option>
      <option value="LA">Louisiana</option>
      <option value="ME">Maine</option>
      <option value="MD">Maryland</option>
      <option value="MA">Massachusetts</option>
      <option value="MI">Michigan</option>
      <option value="MN">Minnesota</option>
      <option value="MS">Mississippi</option>
      <option value="MO">Missouri</option>
      <option value="MT">Montana</option>
      <option value="NE">Nebraska</option>
      <option value="NV">Nevada</option>
      <option value="NH">New Hampshire</option>
      <option value="NJ">New Jersey</option>
      <option value="NM">New Mexico</option>
      <option value="NY">New York</option>
      <option value="NC">North Carolina</option>
      <option value="ND">North Dakota</option>
      <option value="OH">Ohio</option>
      <option value="OK">Oklahoma</option>
      <option value="OR">Oregon</option>
      <option value="PA">Pennsylvania</option>
      <option value="RI">Rhode Island</option>
      <option value="SC">South Carolina</option>
      <option value="SD">South Dakota</option>
      <option value="TN">Tennessee</option>
      <option value="TX">Texas</option>
      <option value="UT">Utah</option>
      <option value="VT">Vermont</option>
      <option value="VA">Virginia</option>
      <option value="WA">Washington</option>
      <option value="WV">West Virginia</option>
      <option value="WI">Wisconsin</option>
      <option value="WY">Wyoming</option>
    </select>
    <div id="location"></div>
    <br>
    <button id='GETJSON'>Get Forecast</button>
    <button id='convert'>Convert Temperature</button>
    <center>
    <div id="forecastContainer">
      <br>
      <div id="forecast"></div>
      <div id="currentDay"></div>
      <div id="currentDate"></div>
      <div id="currentText"></div>
      <div id="currentHigh"></div>
      <div id="currentLow"></div>
      <div id="forecastImageContainer"><img id="forecastImage" src=""></div>
    </div>
    </center>
    <pre id="responseTest"></pre>
  </div>
  </center>
</body>
              
            
!

CSS

              
                h1 {
  color: #0c76b1;  
}

body {
  Xbackground: linear-gradient(90deg, #223271, #45A5FF);
  background-image: url("https://res.cloudinary.com/harunpehlivan/image/upload/v1561458590/Red_Sunset.jpg_zjjpzz.png");
}
#container {
  border: solid #0B315F 5px;
  Xbackground: linear-gradient(90deg, #0B315F, #45A5FF);
  background: #202020;
  opacity: 0.8;
  width: 400px;
  height 400px;
  text-align: center;
  color: #FFF;
  border-radius: 10px;
}
#forecastContainer {
  background-color: #fff;
  opacity: 1;
  border: solid #39386f 5px;
  height: 300px;
  width: 300px;
  text-align: center;
  color: #000;
  border-radius: 10px;
  margin-top: 10px;
}

#forecastImage {
  width: 150px;
}

              
            
!

JS

              
                //declaring and initializing global variables
var currentHigh = 0;
var currentLow = 0;
var tempScale = "F";

//Get Forecast button click function
$('#GETJSON').click(function() {
  //grabbing the city and state from the input boxes and storing them in city and state variables
  var city = $("#city").val();
  var state = $("#state").val();
  //plugging city and state variables into weather API URL to retrieve the weather forecast
  var wURL = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22" + city + "%2C%20" + state + "%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
  $.getJSON(wURL)
    //calling the Update, and Error Handling functions
    .done(update)
    .fail(handleErr);
});

 function update(data) {
    //displaying array for test purposes
   
    //Taking values from the forecast array and storing them in variables
    var forecastTitle = data.query.results.channel.location.city;
    currentHigh = data.query.results.channel.item.forecast[0].high;
    currentLow = data.query.results.channel.item.forecast[0].low;
    var currentText = data.query.results.channel.item.forecast[0].text;
    var currentDate = data.query.results.channel.item.forecast[0].date;
    var currentDay = data.query.results.channel.item.forecast[0].day;
    //displaying the forecast variables into their respective divs
    $('#forecast').html("Forecast for " + forecastTitle);
    $('#currentDay').html(currentDay);
    $('#currentDate').html(currentDate);
    $('#currentText').html(currentText);
    $('#currentHigh').html("High: " + currentHigh + " °F");
    $('#currentLow').html("Low: " + currentLow + " °F");
   //if, else statement to change the src of forecastImage depending on the value of currentText
   //Mostly Sunny & Sunny
   if (currentText == "Mostly Sunny" || currentText == "Sunny") {
     $('#forecastImage').attr('src', 'http://www.free-icons-download.net/images/lovely-sun-icon-57115.png');
   }
   //Thunderstorms & Scattered Thunderstorms
   else if (currentText == "Thunderstorms" || currentText == "Scattered Thunderstorms") {
     $('#forecastImage').attr('src', 'http://orig08.deviantart.net/57de/f/2011/191/f/c/cute_cloud_animated_icon_by_mishavs-d3lnfhq.gif')
   }
   //Rain & Scattered Showers & Showers
   else if (currentText == "Rain" || currentText == "Scattered Showers" || currentText == "Showers") {
     $('#forecastImage').attr('src', 'http://png.clipart.me/graphics/thumbs/211/cute-little-raining-princess-cloud-vector-illustration_211386046.jpg')
   }
   //Snow & Snow Showers & Rain and Snow
   else if (currentText == "Snow" || currentText == "Snow Showers" || currentText == "Rain and Snow") {
     $('#forecastImage').attr('src', 'http://downloadicons.net/sites/default/files/cute-snowman-icon-44183.png')
   }
   //Cloudy & Mostly Cloudy & Partly Cloudy
   else if (currentText == "Cloudy" || currentText == "Mostly Cloudy" || currentText == "Partly Cloudy") {
     $('#forecastImage').attr('src', 'http://png.clipart.me/graphics/thumbs/167/happy-cloud-cartoon-mascot-character-vector-illustration-isolated-on-white_167509646.jpg')
   }
   //Breezy & Windy
   else if (currentText == "Breezy" || currentText == "Windy") {
     $('#forecastImage').attr('src', 'http://png.clipart.me/graphics/thumbs/134/wind-icon-vector_134790392.jpg')
   }
   //Clear & Mostly Clear
   else if (currentText == "Clear" || currentText == "Mostly Clear") {
     $('#forecastImage').attr('src', 'http://a.deviantart.net/avatars/m/e/mew-girl.gif?2')
   }

//data.query.results.channel.item.forecast
   
}

//Button for converting between F and C temp scales
$('#convert').click(function() {
  //If F, convert to C
  if (tempScale == "F") {
    // C = (F-32) x (5/9)
    //parseFloat converts the string into a floating decimal number
    currentHigh = (parseFloat(currentHigh) - 32) * (5/9);
    currentLow = (parseFloat(currentLow) - 32) * (5/9);
    //put the new currentHigh and currentLow into the respective divs along with their label
    // .toFixed is used so that only 2 digits after the decimal are displayed
    $('#currentHigh').html("High: " + (currentHigh).toFixed(2) + " °C");
    $('#currentLow').html("Low: " + (currentLow).toFixed(2) + " °C");
    //change tempScale to C
    tempScale = "C";
  }
  //If C, convert to F
  else {
    // F = (C x (9/5)) + 32
    //parseFloat converts the string into a floating decimal number
    currentHigh = parseFloat(currentHigh) * (9/5) + 32;
    currentLow = parseFloat(currentLow) * (9/5) + 32;
    //put the new currentHigh and currentLow into the respective divs along with their label
    // .toFixed is used so that only 2 digits after the decimal are displayed
    $('#currentHigh').html("High: " + currentHigh + " °F");
    $('#currentLow').html("Low: " + currentLow + " °F");
    //change tempScale to F
    tempScale = "F";
  }
});

function handleErr(jqxhr, textStatus, err) {
    //reports an error if there is one
    console.log("Request Failed: " + textStatus + ", " + err);
}


              
            
!
999px

Console