Tuesday, 15 April 2014

javascript - Temperature conditions -



javascript - Temperature conditions -

i have problem these conditions. body changes color depending on temperature. works lastly color considered '#e74c3c' . illustration 15 degrees , reddish '#e74c3c' not 30 °.

if(weather.temp > 0) { $('body').animate({backgroundcolor: '#3498db'}, 1500); } else { $('body').animate({backgroundcolor: '#3498db'}, 1500); } if(weather.temp > 10) { $('body').animate({backgroundcolor: '#f1c40f'}, 1500); } else { $('body').animate({backgroundcolor: '#f1c40f'}, 1500); } if(weather.temp > 20) { $('body').animate({backgroundcolor: '#f39c12'}, 1500); } else { $('body').animate({backgroundcolor: '#f39c12'}, 1500); } if(weather.temp > 30) { $('body').animate({backgroundcolor: '#e74c3c'}, 1500); } else { $('body').animate({backgroundcolor: '#e74c3c'}, 1500); }

because final else triggered <= 30. should utilize 1 if, , several else ifs after it.

if (weather.temp <= 10) { $('body').animate({ backgroundcolor: '#3498db' }, 1500); } else if (weather.temp > 10 && weather.temp <= 20) { $('body').animate({ backgroundcolor: '#f1c40f' }, 1500); } else if (weather.temp > 20 && weather.temp <= 30) { $('body').animate({ backgroundcolor: '#f39c12' }, 1500); } else if (weather.temp > 30) { $('body').animate({ backgroundcolor: '#e74c3c' }, 1500); }

javascript jquery

No comments:

Post a Comment