JavaScript/Loops/Exercises

Topic: Loops

for (Part 1)
{What is the result?

- Numbers from 3 to 5 - Numbers from 3 to 6 + Runtime error - None of the above
 * type=""}

{What is the result?

- Numbers from 10 to 0 + Even Numbers from 10 to 0 - Odd Numbers from 10 to 0 - Runtime error - None of the above
 * type=""}

{What is the result?

- 5, 8 - 5, 8, 8 - 5, 8, 11 + 5, 8, 8, 11 - Runtime error - None of the above
 * type=""}

{What is the result?

- a, b, c + c, b, a - Runtime error - None of the above
 * type=""}

for (Part 2)
1. Write a script that uses two nested loops and shows the following strings:

2. Write a script that uses two nested loops and shows the following strings, including the apostrophes: (Bonus challenge: Remove the last comma)

3. Write a script that creates a 'quadrat' with edge length 4. It consists of 'x's at one diagonal and dots at the other places. Hint: Create an empty string and - within the loop - append characters to the string. The line break is "\n". Lastly, show the string.
 * Use  loops.
 * In a second step, change only one single statement to create an according 6 x 6 quadrat.

4. Write a script that creates an 'arrow' with two heads: "<======>". The length of the arrow is determined by a variable. Changing this variable will result in an arrow of a different size.

for..in, for..of, entries
1. Write a script that
 * creates an Object with some of your personal characteristics
 * shows all properties (key and value) within a for..in loop
 * shows all properties (key and value) by using the Object.entries method.

2. Write a script that
 * creates an Array with all odd numbers smaller than 10
 * creates a string with all those numbers plus a delimiter using a for..of loop
 * shows the string after the loop

{What is the result?

+ 0, 1, 2 followed by 10, 11, 12 - 10, 11, 12 followed by 0, 1, 2 - Runtime error
 * type=""}

{What is the result?

- 0, 1, 2 + 10, 11, 12 - Runtime error
 * type=""}

forEach
1. Write a script that
 * defines an array
 * use a  construction to fill a second array with the quadratic values (9, 64, ...) of the first array
 * show the second array