-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion1.js
35 lines (31 loc) · 846 Bytes
/
question1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var readlineSync = require('readline-sync');
function f() {
var inputNumber = readlineSync.question("Please enter a number : ");
if (inputNumber == "q") {
return;
} else if (inputNumber != Number(inputNumber)) {
console.log("invalid input");
f();
} else if (Number(inputNumber) % 2 == 0) {
console.log("even");
exit();
} else if (Number(inputNumber) % 2 != 0) {
console.log("Odd");
exit();
} else {
return;
}
}
function exit() {
var inputBool = readlineSync.question("Do you want to continue (Y/n): ")
if (inputBool == "y" || inputBool == "Y") {
f();
} else if (inputBool == "n") {
console.log("Thank you, Goodbye!");
return;
} else {
console.log("invalid response.");
exit();
}
}
f();