BananaMaster

29 - Template literals in the for loop ``, increment and decrement (JS lessons)

If you forgot something, click to go to the lesson

Task 1.

Create a 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 loop from 10 to 1. Output all numbers in a single console.log. Result: 10 9 8 7 6 5 4 3 2 1

Task 3.

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

Task 4.

Create a div on the page. Make a loop from 1 to 10. On each iteration, multiply the number by 2, create a separate <p> tag, and output the result using a template literal. Output format:

<p>2 * 1 = 2</p>

<p>2 * 2 = 4</p>

...

<p>2 * 10 = 20</p>

Task 5.

Create a ul on the page. Make a loop from 1 to 8. Wrap each element in an <li> tag using a template literal. Text inside: Item 1, Item 2, and so on. Output the result into the <ul> tag.

Task 6.

Create an input, a div, and a button. The user enters a number. Create a countdown loop from the entered number down to 1. Output each step into the div inside a separate <p> tag using template literals.

After the loop, add <p>GO!</p>

Result when entering 5:

5

4

3

2

1

GO!

Task 7.

Create an input for a name, an input for a count, a div, and a button. The user enters a name and a number. Make a loop from 1 to the entered number. Output the result in the div, placing each entry in a separate <p> tag using a template literal.

Result if the user entered User and 3:

<p>User</p>

<p>User</p>

<p>User</p>