How to print the season name of the year based on the month number in JavaScript

1 Answer

0 votes
function printSeason(month) {
    switch (month) {
        case 12:
        case 1:
        case 2:
            console.log("Winter");
            break;
        case 3:
        case 4:
        case 5:
            console.log("Spring");
            break;
        case 6:
        case 7:
        case 8:
            console.log("Summer");
            break;
        case 9:
        case 10:
        case 11:
            console.log("Autumn");
            break;
        default:
            console.log("Invalid month number!");
            break;
    }
}


let month = 9;

printSeason(month);


/*
run:

Autumn

*/

 



answered Sep 10, 2025 by avibootz
edited Sep 10, 2025 by avibootz
...