Can you give the code in Javascript?
- User
Can you give the code in Javascript?
Assistant
Sure! Here is a simple FizzBuzz solution in JavaScript that prints the sequence from 1 to 100:
javascriptfor (let i = 1; i <= 100; i++) { let output = ""; if (i % 3 === 0) { output += "Fizz"; } if (i % 5 === 0) { output += "Buzz"; } console.log(output || i); }How it works:
- Iterates through numbers 1 to 100 using a
forloop. - Builds the
outputstring progressively:- Appends "Fizz" if the number is divisible by 3.
- Appends "Buzz" if the number is divisible by 5.
- Uses short-circuit evaluation:
- Iterates through numbers 1 to 100 using a
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.