HackerRank Loops | JS Solution

HackerRank Loops | JS Solution

Problem

HackerRank detailed problem description can be found here.

Inputs & Outputs

/*
input {number} n
output {string} n x i = result
*/

Test Case

n = 5;

JavaScript Solution

function main() {
  const n = parseInt(readLine(), 10);

  if (!n || typeof n !== 'number') {
    return;
  }

  for (let i = 1; i < 11; i++) {
    console.log(`${n} x ${i} = ${n * i}`);
  }
}

Resources

  1. Loops algorithm by HackerRank
  2. typeof by MDN Web Docs
  3. Template literals by MDN Web Docs