-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1074.js
27 lines (21 loc) · 976 Bytes
/
1074.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
// Read an integer value N. After, read these N values and print a message for each value saying if this value is odd, even, positive or negative. In case of zero (0), although the correct description would be "EVEN NULL", because by definition zero is even, your program must print only "NULL", without quotes.
// Input
// The first line of input is an integer N (N < 10000), that indicates the total number of test cases. Each case is a integer number X (-107 < X <107)
const n = 5;
const arr = [4, -5, 0, 3, -4];
for (let i = 0; i < arr.length; i++) {
const num = arr[i];
let isPositive = num > 0;
let isEven = num % 2 === 0;
if (num === 0) {
console.log(num, "null");
} else if (isEven && !isPositive) {
console.log(num, "even negative");
} else if (!isEven && !isPositive) {
console.log(num, "odd negative");
} else if (!isEven && isPositive) {
console.log(num, "odd positive");
} else {
console.log(num, "even positive");
}
}