I’m doing the 30 Days of Code on HakerRank.com. I’m Day 5: Loops, yikes! It’s been a couple of days…lets dive into it.

This challenge is categorized as Easy, Max Score is 30, and the Success Rate is 98.66%.

The Objective is:

In this challenge, we will use loops to do some math.

note: for some reason the less than or equal to symbol is showing as the £, British Pound symbol, so i just wrote it out the (less than or equal to symbol) in parentheses.

The Task is:

Given an integer, n, print its first 10 multiples.

Each multiple n x i (where 1 (less than or equal to symbol) i (less than or equal to symbol) 10 ) should be printed on a new line in the form: n x i = result.

Example:

n = 3

The printout should look like this:

3 x 1 = 3

3 x 2 = 6

3 x 3 = 9

3 x 4 = 12

3 x 5 = 15

3 x 6 = 18

3 x 7 = 21

3 x 8 = 24

3 x 9 = 27

3 x 10 = 30

Input Format

A single integer, n.

Constraints:

2 (less than or equal to symbol) n (less than or equal to symbol) 20

Output Format:

Print 10 lines of output; each line i (where 1 (less than or equal to symbol) i (less than or equal to symbol) 10) contains the result of n ´ i in the form:

n x i = result.

Sample Input:

2

Sample Output:

2 x 1 = 2

2 x 2 = 4

2 x 3 = 6

2 x 4 = 8

2 x 5 = 10

2 x 6 = 12

2 x 7 = 14

2 x 8 = 16

2 x 9 = 18

2 x 10 = 20

Not much instruction is given.

Ok, so here is what is provided in the text editor on the website for JavaScript (Node.js):

// Everything in RED is hidden

‘use strict’;

process.stdin.resume();

process.stdin.setEncoding(‘utf-8’);

let inputString = ‘’;

let currentLine = 0;

process.stdin.on(‘data’, function(inputStdin) {

inputString += inputStdin;

});

process.stdin.on(‘end’, function() {

inputString = inputString.split(‘\n’);

main();

});

function readLine() {

return inputString[currentLine++];

}

// Everything is GREEN is what is supposed to be worked on.

function main() {

const n = parseInt(readLine().trim(), 10);

}

So we’re supposed to take a user input, initialize a loop with i = 0 and add two conditions i <= 10 and i++, then multiply i and n and console.log the result.

For this a simple for loop is gonna be used.

we’re gonna:

let i = 1

and then i be less than or equal to 10

and then i increment by 1.

The FOR LOOP will run until i is less than or equal to 10.

And maybe we console.log the arithmetic operations

So, let’s write it out in code.

Function main() {

const n = parseInt(readLine().trim(), 10);

for (let i = 1; i (less than or equal to symbol) 10; i++ ) {

console.log(`${n} x ${i} = ${n * i}`)

}

}

Wowzers, not bad.

I said it before and I’ll say it again:

I’m glad I started doing the 30 Days of Code on HakerRank.com.

I haven’t been consistent with trying the challenges everyday but after each challenge, I’m glad I do it. Hopefully, this gives me enough reason to remain consistent and finish within 25 days.

If you want to start on the 30 Days of Code on HakerRank.com just click on the underlined and highlighted text on this sentence. I’m sure you’ll enjoy it like I did and you’ll have learned something new.

P.S. I earned my first start on HackerRank!

The Scoring Documentation says, “You earn badges by solving challenges on the various practice tracks on our site. If you solve a challenge in an official HackerRank contest, you will earn points towards your progress once the challenge is added to the practice site.”

Hello, I am a young enthusiastic Software Engineer. Looking forward to an opportunity to use my skills for mutual benefits and growth as well.