HackerRank Conditional Statements | JS Solution

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

  1. Intro to Conditional Statements by HackerRank
  2. JavaScript Arithmetic Operators by W3Schools
  3. JavaScript Comparison and Logical Operators by W3Schools