HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
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;
}
//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);
}
Also see: Tab Triggers