Write fizzbuzz in javascript
- User
Write fizzbuzz in javascript
Assistant
Sure, I'd be happy to help! Here's one way to write "FizzBuzz" in JavaScript:
function fizzbuzz(n) { if (n % 3 === 0 && n % 5 === 0) { return "FizzBuzz"; } else if (n % 3 === 0) { return "Fizz"; } else if (n % 5 === 0) { return "Buzz"; } else { return n; } }
For example, if we call the
fizzbuzzfunction with the argument10, it will return "FizzBuzz" because 10 is both divisible by 3 and 5. If we call it with the argument4, it will return "Fizz" because 4 is only divisible by 3. If we call it with the argument9, it will return "Buzz" because 9 is only divisible by 5. If we call it with any other number, it will simply return that number.I hope this helps! Let me know if you have any other questions.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.