JavaScript: Little Codes

Weather

<label for="weather">Select the weather type today: </label>
<select id="weather">
    <option value="">--Make a choice--</option>
    <option value="sunny">Sunny</option>
    <option value="rainy">Rainy</option>
    <option value="snowing">Snowing</option>
    <option value="overcast">Overcast</option>
</select>

<p id="weatherBox"></p>

<script>
    const userWeather = document.querySelector('select');
    const weatherAdvice = document.querySelector('#weatherBox');

    userWeather.addEventListener('change', weatherFunction);

    function weatherFunction() {
        if (userWeather.value === 'sunny') {
            weatherAdvice.textContent = 'It is nice and sunny outside today. Wear shorts! Go to the beach, or the park, and get an ice cream.';
        } else if (userWeather.value === 'rainy') {
            weatherAdvice.textContent = 'Rain is falling outside; take a rain coat and an umbrella, and don\'t stay out for too long.';
        } else if (userWeather.value === 'snowing') {
            weatherAdvice.textContent = 'The snow is coming down — it is freezing! Best to stay in with a cup of hot chocolate, or go build a snowman.';
        } else if (userWeather.value === 'overcast') {
            weatherAdvice.textContent = 'It isn\'t raining, but the sky is grey and gloomy; it could turn any minute, so take a rain coat just in case.';
        } else {
            weatherAdvice.textContent = '';
        }
    }
</script>