JS 4.3 Loops Flashcards

1
Q

Define a ( while ) statement

A

A ( while ) statement creates a loop that executes a specified statement as long as the test condition evaluates to true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s the difference between the ( do ) loop and the ( while ) loop?

A

The do while loop executes a block a code before the condition is tested. A while loop test its condition first before it executes a block of code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s the syntax for a do ( while loop )?

A

The keyword do, followed by curly braces and then the keyword while followed by parentheses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the syntax for a ( for loop)?

A

Use the keyword ‘for’, followed by parentheses, which hold the initial expression, condition expression and then the increment expression.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define the ( break ) statement

A

Terminates the current loop, switch, or label statement and transfers program control to the statement following the terminated statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

As far as DRY code using JavaScript, what are three big principles?

A
  1. Reduce repetition of code in a program
  2. Loops help you write DRY code
  3. JavaScript functions embrace the DRY principle
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define the ( document.querySelector() ) method

A

This method returns the first element within the document that matches that specified selector or a group of selectors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly