DEV Community

Cover image for ๐Ÿ‘จโ€๐Ÿ’ป Daily Code 43 | FizzBuzz Exercise in ๐Ÿ Python and ๐ŸŸจ JavaScript (round 2!)
Gregor Schafroth
Gregor Schafroth

Posted on

๐Ÿ‘จโ€๐Ÿ’ป Daily Code 43 | FizzBuzz Exercise in ๐Ÿ Python and ๐ŸŸจ JavaScript (round 2!)

Alright as promised, today Iโ€™ll try to do the FizzBuzz exercise again. Iโ€™ll try to make the solution elegant without looking at yesterdays solution.

My Code

๐Ÿ Python:

for number in range(1, 101):
    result = ""
    if number % 3 == 0:
        result += "Fizz"
    if number % 5 == 0:
        result += "Buzz"
    print(result or number)
Enter fullscreen mode Exit fullscreen mode

๐ŸŸจ JavaScript

for (number = 1; number < 101; number++) {
    let result = "";
    if (number % 3 === 0) {
        result += "Fizz";
    } if (number % 5 === 0) {
        result += "Buzz";
    }
    console.log(result || number);
}
Enter fullscreen mode Exit fullscreen mode

Nice! Looks like I was able to nail it this time. The only further suggestions I get from ChatGPT on how to improve these is add comments and put them in a function, which are easy things to do.

Alright thatโ€™s it for today. Tomorrow Iโ€™ll do a new exercise again โŒจ๏ธ ๐Ÿ˜Š

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs