BananaMaster

34 - The while loop and its syntax (JS lessons)

If you forgot something, click to go to the lesson

Task 1.

Create a while loop from 1 to 10. Output all numbers in a single console.log. Result: 1 2 3 4 5 6 7 8 9 10

Task 2.

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

Result:

100

200

..

1000

Task 3.

Create a while loop from 10 down to 1. Output each number multiplied by 2 to the console.

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 while loop from 1 to the entered number. Output all numbers in a div.

Task 5.

Create a while loop from 0 to 20. Output only even numbers to the console.

Task 6.

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

Task 7.

Create a div on the page. Make a while loop from 1 to 7. Wrap each number in a <p> tag using a template literal. Output everything into the div.