Practice & Assessment
Test your understanding of Control Flow and Functions
Multiple Choice Questions
5Which of the following values is falsy in JavaScript?
What is the output of the following code? for (let i = 0; i < 3; i++) { console.log(i); }
What is the key difference between a regular function and an arrow function regarding 'this'?
What is a closure in JavaScript?
Which loop always executes its body at least once?
Coding Challenges
1FizzBuzz with Functions
Write a JavaScript function called fizzBuzz(n) that loops from 1 to n. For multiples of 3, log 'Fizz'. For multiples of 5, log 'Buzz'. For multiples of both, log 'FizzBuzz'. Otherwise log the number. Call the function with n = 30.
Mini Project
Number Guessing Game
Build a number guessing game in the browser. Generate a random number between 1 and 100 using Math.random(). Prompt the user for guesses using a while loop and window.prompt(). After each guess, tell the user if the number is too high, too low, or correct. Count the number of attempts. When the user guesses correctly, display a congratulations message with the attempt count. Use functions for generating the number, checking the guess, and displaying feedback.
