Activity 4
Correct Answers
1. How to run array-related operations efficiently? ✅ Use loops like for or while in combination with methods.
2. What is the condition part in a for loop? ✅ It determines when the loop stops.
3. How to loop over converted object keys? ✅ Convert keys to arrays, then use loops.
4. Which loop conditionally executes a block? ✅ While loop
5. What is the output for even numbers 0-10? ✅ "0, 2, 4, 6, 8, 10"
6. How do you combine arrays with loops? ✅ Use the length property with a loop condition.
7. What is the for-in loop used for? ✅ Iterating over object properties.
8. What is a key feature of a do-while loop? ✅ It runs the code block at least once before checking.
9. What are the components of a for loop? ✅ Initialization, condition, increment/decrement.
10. What happens in a do-while with false conditions? ✅ The block runs once before stopping.
Instructions:
Set Up Your Development Environment
- Open your preferred code editor (e.g., VS Code, Sublime Text, or Notepad++).
- Create a new file and save it with the .html extension (e.g., LoopsActivity.html).
Implement JavaScript Loops
- Create buttons to trigger different loop types:
- While Loop
- Do While Loop
- For Loop
- Finding a Value in an Array
- Creating an Array
- Nested Loops
- Each button should trigger the respective JavaScript function.
- Display alerts notifying users when loops are running.
- Log results to the console.