HackerRank Conditional Statements | JS Solution
Problem
HackerRank detailed problem description can be found here.
Inputs & Outputs
/*
input {number} N
output {string} 'Weird' || 'Not Weird'
*/
Test Case
N = 24;
JavaScript Solution
function main() {
const N = parseInt(readLine(), 10);
if (N % 2 === 0) {
if ((N >= 2 && N <= 5) || N > 20) {
console.log('Not Weird');
} else if (N >= 6 && N <= 20) {
console.log('Weird');
}
} else {
console.log('Weird');
}
}
Resources
- Intro to Conditional Statements by HackerRank
- JavaScript Arithmetic Operators by W3Schools
- JavaScript Comparison and Logical Operators by W3Schools