please make a fizz buzz app in javascript
- User
please make a fizz buzz app in javascript
Assistant
Here is a simple FizzBuzz app in JavaScript:
function fizzBuzz(num) { for (let i = 1; i <= num; i++) { if (i % 15 === 0) { console.log("FizzBuzz"); } else if (i % 3 === 0) { console.log("Fizz"); } else if (i % 5 === 0) { console.log("Buzz"); } else { console.log(i); } } } // Example usage fizzBuzz(100);How it works:
- The fizzBuzz function takes a number as a parameter
- It loops from 1 to that number
- Inside the loop it checks:
- If the number is divisible by 15, log "FizzBuzz"
- Else if divisible by 3, log "Fizz"
- Else if divisible by 5, log "Buzz"
- Else just log the number
- This prints out the FizzBuzz sequence up to the given number
Some key points:
- Uses modulo (%) to check for divisibility
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.