assets/js/script.js
// A function to give the UV Index background a color depending on the reading
A function to give the UV Index background a color depending on the reading
A function to give the UV Index background a color depending on the reading
function uvColor(uvIndexValue, uvInfo) {
    let uvIndexSpan = document.querySelector('.uv-index-color');
    let uvIndexInfoSpan = document.querySelector('.uv-index-info');
    if(uvIndexValue >= 0 && uvIndexValue < 3) {
        uvIndexSpan.setAttribute('style', 'background: #33bc33; color: #fff; cursor: help; padding: 0.2rem 0.9rem;');
        uvInfo = 'Low exposure level';
        uvIndexInfoSpan.innerHTML = uvInfo;
    }
    else if(uvIndexValue >= 3 && uvIndexValue < 6) {
        uvIndexSpan.setAttribute('style', 'background: #fffc2b; color: #000; cursor: help; padding: 0.2rem 0.9rem;');
        uvInfo = 'Moderate exposure level';
        uvIndexInfoSpan.innerHTML = uvInfo;
    }
    else if(uvIndexValue >= 6 && uvIndexValue < 8) {
        uvIndexSpan.setAttribute('style', 'background: #ff9c2f; color: #fff; cursor: help; padding: 0.2rem 0.9rem;');
        uvInfo = 'High exposure level';
        uvIndexInfoSpan.innerHTML = uvInfo;
    }
    else if(uvIndexValue >= 8 && uvIndexValue <= 10) {
        uvIndexSpan.setAttribute('style', 'background: #fa2f2f; color: #fff; cursor: help; padding: 0.2rem 0.9rem;');
        uvInfo = 'Very high exposure level';
        uvIndexInfoSpan.innerHTML = uvInfo;
    }
    else {
        uvIndexSpan.setAttribute('style', 'background: #ff0000; color: #fff; cursor: help; padding: 0.2rem 0.9rem;');
        uvInfo = 'Extreme exposure level';
        uvIndexInfoSpan.innerHTML = uvInfo;
    }
}
function uvColor ( uvIndexValue , uvInfo ) { let uvIndexSpan = document . querySelector ( '.uv-index-color' ) ; let uvIndexInfoSpan = document . querySelector ( '.uv-index-info' ) ; if ( uvIndexValue >= 0 && uvIndexValue < 3 ) { uvIndexSpan . setAttribute ( 'style' , 'background: #33bc33; color: #fff; cursor: help; padding: 0.2rem 0.9rem;' ) ; uvInfo = 'Low exposure level' ; uvIndexInfoSpan . innerHTML = uvInfo ; } else if ( uvIndexValue >= 3 && uvIndexValue < 6 ) { uvIndexSpan . setAttribute ( 'style' , 'background: #fffc2b; color: #000; cursor: help; padding: 0.2rem 0.9rem;' ) ; uvInfo = 'Moderate exposure level' ; uvIndexInfoSpan . innerHTML = uvInfo ; } else if ( uvIndexValue >= 6 && uvIndexValue < 8 ) { uvIndexSpan . setAttribute ( 'style' , 'background: #ff9c2f; color: #fff; cursor: help; padding: 0.2rem 0.9rem;' ) ; uvInfo = 'High exposure level' ; uvIndexInfoSpan . innerHTML = uvInfo ; } else if ( uvIndexValue >= 8 && uvIndexValue <= 10 ) { uvIndexSpan . setAttribute ( 'style' , 'background: #fa2f2f; color: #fff; cursor: help; padding: 0.2rem 0.9rem;' ) ; uvInfo = 'Very high exposure level' ; uvIndexInfoSpan . innerHTML = uvInfo ; } else { uvIndexSpan . setAttribute ( 'style' , 'background: #ff0000; color: #fff; cursor: help; padding: 0.2rem 0.9rem;' ) ; uvInfo = 'Extreme exposure level' ; uvIndexInfoSpan . innerHTML = uvInfo ; } }
A function to give the UV Index background a color depending on the reading
A function to give the UV Index background a color depending on the reading