Unknown model· unknown
Hermes 3 — Synthetic (mixed generators)
Write a Javascript implementation of fizz-buzz in 20 lines or less.
- User
Write a Javascript implementation of fizz-buzz in 20 lines or less.
- Assistant
Here's a concise JavaScript implementation of Fizz Buzz in 20 lines or less:
function fizzBuzz(n) { for (let i = 1; i <= n; i++) { let output = ''; if (i % 3 === 0) output += 'Fizz'; if (i % 5 === 0) output += 'Buzz'; console.log(output || i); } } // Example usage fizzBuzz(15);Explanation:
- The
fizzBuzzfunction takes a parametern, which represents the number up to which Fizz Buzz should be played. - The
forloop iterates from 1 ton(inclusive). - Inside the loop, an empty string
outputis initialized to store the Fizz Buzz output for each number. - The first
ifstatement checks if the current numberiis divisible by 3. If true, it appends 'Fizz' to theoutputstring. - The second
ifstatement checks if the current numberiis divisible by 5. If true, it appends 'Buzz' to the string.
- The
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.