diff --git a/assets/js/ci-openweather.js b/assets/js/ci-openweather.js index dfa30ea..ca452eb 100644 --- a/assets/js/ci-openweather.js +++ b/assets/js/ci-openweather.js @@ -45,9 +45,11 @@ const weatherIconCode = weatherData.list[0].weather[0].icon; const weatherIcon = `http://openweathermap.org/img/w/${weatherIconCode}.png`; const weatherTemperatureValue = `${parseInt(weatherData.list[0].main.temp)}`; - let weatherTemperatureDegree = 'K'; - weatherOptionsValues.unit = 'metric' ? weatherTemperatureDegree = '°C' : weatherTemperatureDegree = '°F'; - const weatherTemperature = `${weatherTemperatureValue}${weatherTemperatureDegree}`; + const weatherTemperatureDegrees = [{'standard': 'K'}, {'metric': 'C'}, {'imperial': 'F'}]; + const weatherTemperatureDegree = weatherTemperatureDegrees + .filter( obj => weatherOptionsValues.unit in obj) + .map(obj => obj[weatherOptionsValues.unit]); + const weatherTemperature = `${weatherTemperatureValue}°${weatherTemperatureDegree}`; const outputDiv = document.querySelectorAll('.weather-output'); outputDiv.forEach( item => {