Select Page

Task of Challenge #01/54

Print numbers from 1 to 10 with a for-loop .

Solution

Explanation

We just need to print out ten numbers to the console prompt. A for-loop is the perfect tool for this job! We create a loop with a running index of i with the starting value of 1.

The loop will stop once i reaches the value of 11, so when i equals 10, the loop will execute the last execution because we created the condition of i <= 10.

The running index will be increased by 1 every iteration. i++ is the corresponding statement for that. It is the short form for i = i+1.

Inside the loop we got our statement of console.log(i); which prints out, whatever is inside the brace, to the console window.

Follow me on Instagram and don’t miss the latest Challenge!

https://www.instagram.com/arnold.code/

Gather more Knowledge about JavaScript?

Here are two pre-picked and high quality Medium articles for you.