BananaMaster

28 - How to use a for loop to work with HTML (JS lessons)

If you forgot something, click to go to the lesson

Task 1.

Create a loop from 1 to 10. Output each number in a p tag using innerHTML.

Result:

1

2

..

10

Task 2.

Create a loop from 1 to 10. Display the numbers: 100 200 300 ... 900 1000, placing each number inside an h3 tag.

Result:

100

200

..

1000

Task 3.

Create a loop from 5 to 50. Output the numbers in a div. Result: 5 10 15 20 25 30 35 40 45 50

Task 4.

Create an input and a button on the page. The user types a number into the input and clicks the button. Create a loop from 1 to the entered number. Output all numbers in a div.

Task 5.

Create a select with options 3, 5, 10, 15, a button, and a div. On click, create a loop from 1 to the selected value in the select. Output the result in the div.

Task 6.

Create two input fields, a div, and a button. The user enters two numbers — the start and end of the loop. Create a loop from the first number to the second and output the result in the div.

Task 7.

Create two p elements and make a loop from -7 to 7. Numbers less than 0 go into one p, numbers greater than 0 go into the other. Skip 0.

The result should look like this:

Positive: 1 2 3 4 5 6 7

Negative: -1 -2 -3 -4 -5 -6 -7