I have succeeded in parsing a response from the Wunderground API and displaying a response for the "current" weather conditions of a state and certain city. This tells me the exact temp and current conditions outside at the time of the call.
I now need the ability and I am having trouble getting a 3 day forecasted response to work along with the current weather condition response I have.
My end result I want a 3 day forecasted result and all of those days to contain High and Low Temps for those days only.
Example:
- Day 01 - Monday High / Low
- Day 02 - Tuesday High / Low
- Day 03 - Wednesday High / Low
Day 01 would technically be the current day it is.
Please if anyone can take a look at my script as of now and help add what is missing I would appreciate it.
Here is my JS
jQuery(document).ready(function($) {
/* Edit these variables */
var api = "2ea138a9dd52eabe";
var state = "TX";
var city = "Dallas";
$.ajax({
url: "http://api.wunderground.com/api/" + api + "/forecast/conditions/q/" + state + "/" + city + ".json",
dataType : "jsonp",
success : function(parsed_json) {
var icon_url_json = "http://icons.wxug.com/i/c/f/" + parsed_json['current_observation']['icon'] + ".gif";
var icon_json = '<img src ="' + icon_url_json + '" />';
var temp_json = parsed_json['current_observation']['temp_f'];
temp_json += "<span>°F</span>";
var condition_json = parsed_json['current_observation']['weather'];
var real_feel_json = "Feels Like " + parsed_json['current_observation']['feelslike_f'] + "°F";
var wind_json = 'Winds are ' + parsed_json['current_observation']['wind_string'];
var location_json = city + ', ' + state;
var forecastArray = parsed_json['forecast']['txt_forecast']['forecastday'];
if (forecastArray !== null) {
for (var i = 0; i < forecastArray.length; i++) {
if (forecastArray[i] !== null) {
//use can use this to assing directly to HTML element
console.log(forecastArray[i]['period']);
console.log(forecastArray[i]['title']);
console.log(forecastArray[i]['fcttext']);
}
}}
document.getElementById("weather-icon").innerHTML = icon_json;
document.getElementById("temp").innerHTML = temp_json;
document.getElementById("condition").innerHTML = condition_json;
document.getElementById("real-feel").innerHTML = real_feel_json;
document.getElementById("wind").innerHTML = wind_json;
document.getElementById("location").innerHTML = location_json;
}
});
});
I have also put this up here for people to look at it working as of now. http://jsfiddle.net/supasmo/9d5bh/2/