Answer to Question #295112 in HTML/JavaScript Web Application for chethan

Question #295112

given month as an input write a js program to find corresponding season using switch statment

input1

January

output1

winter

input2

may

output2

summer

input3

october

output3

autumn


"use strict";


process.stdin.resume();

process.stdin.setEncoding("utf-8");


let inputString = "";

let currentLine = 0;


process.stdin.on("data", (inputStdin) => {

 inputString += inputStdin;

});


process.stdin.on("end", (_) => {

 inputString = inputString.trim().split("\n").map((str) => str.trim());

 main();

});


function readLine() {

 return inputString[currentLine++];

}


function main() {

 const month = readLine();


/* Please do not modify anything above this line */


 // Write your code here

}











1
Expert's answer
2022-02-09T14:54:03-0500
"use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
 inputString = inputString.trim().split("\n").map((str) => str.trim());
 main();
});

function readLine() {
    return inputString[currentLine++];
}

function main() {
    const month = readLine();

    // Write your code here
    switch(month.toLowerCase()) {
        case 'december':
        case 'janyary':
        case 'february':
            return 'Winter'
        case 'march':
        case 'april':
        case 'may':
            return 'Spring'
        case 'june':
        case 'july':
        case 'august':
            return 'Summer'
        case 'september':
        case 'october':
        case 'november':
            return 'Autumn'
        default:
            return 'This month does not exist.'
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS