I'm using Yahoo Weather and there are about 47 weather conditions from 0 to 47 each number represents the condition of the weather.
I want to get the condition for 4 days , today and the next 3 days so there will be a very long code of switch statements if I use a switch statement for each.
My code now for today condition:
var src = ""; //This variable will contain an icon that represents the weather condition.
switch(todayCondition){ //todayCondition is today condition it's in the range [0-47]
case "0":
src = 'storm.svg';
break;
........
........
case "47":
src = 'rain.svg';
break;
}
document.getElementById('todayWeatherIcon').src = src;
The html:
<img id = 'todayWeatherIcon' />
There are 3 other variables for the next 3 days conditions that will be from 0-47 too and will have the same icons depending on the number.
How to do the same thing for the other 3 variables without repeating the same code?
"condition<some number>Img.png"? If so, why not get rid of the switch completely and just dosrc = "condition" + todayCondition + "Img.png";? Then repeat that for each day.0..47, you can usevar src = arrayOfIconNames[todayCondition];