Problem 10. oddeven.js

 /*Question

Even or Odd
Given a postive integer, find out whether it is even or odd.

Input
One line containing a positive integer.

Output
One line containing a string. Odd if the given integer is odd and Even if the given integer is
even.

Example
Input:

9
Output:

Odd
*/

let fs = require("fs");
let data = fs.readFileSync(0, 'utf-8');
let idx = 0;
data = data.split('\n');

function readLine() {
idx++;
return data[idx - 1].trim();
}
//...........................................................................................

let integer = parseInt(readLine()); // 9

if (integer % 2 == 0) {
console.log("Even"); // 9%2 = 1 which is not == 0, therefore go to the else part
}

else {
console.log("Odd");
}

Terminal:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node oddeven.js <input.txt Odd

Comments

Popular posts from this blog

Problem 33. patter122333.js

Problem 38. diamond.js

Problem 16. chocolatebills.js