Activity 3
Correct Answers
1. What is a switch statement best used for? ✅ Checking multiple potential values
2. What mistake is common with if statements? ✅ Using the assignment operator (=)
3. What is the default case in a switch statement for? ✅ Executes when no cases match
4. What happens if no break statement is used in a switch case? ✅ All subsequent cases execute
5. What type of values does a ternary operator return? ✅ Any value based on conditions
6. What is the purpose of the else statement? ✅ Executes if the if condition is false
7. In an if-else statement, what happens when the if condition is true? ✅ The if block runs
8. What happens without a break statement in a switch case? ✅ Fall-through to subsequent cases
9. Which block evaluates multiple conditions sequentially? ✅ if-else if
10. What does an if statement do in JavaScript? ✅ Executes a block if the condition is true
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., ConditionalsActivity.html).
Implement JavaScript Conditional Statements
- Create buttons to trigger different conditional statements:
- If Statement
- If-Else Statement
- Else If Statement
- Conditional (Ternary) Operator
- Switch Statement
- Clear Console
- Each button should trigger the respective JavaScript function.
- Display alerts notifying users when conditionals are being executed.
- Log results to the console.