Fun with Fizz Buzz!

I found FizzBuzz by accident a week ago. So what is FizzBuzz. It is a programming task where you have to create the following:

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

So I did that, don't look yet but first read till the end.

My solution

Then I asked my son @bartmathijssen what he would do. So he made his version.

Bart's solution

Would you have another solution to the FizzBuzz question?

  • Could you make one with the webviewer and javascript?

  • Could you use Skulpt, where you can run Python inside an App Inventor app.

  • Could you use a FizzBuzz api to get the results https://fizzbuzz.ketzu.net/to/100 and pass the json code into a label.

  • Maybe run a php script on a server and get the results.

  • Etc, etc.

You can post your solutions below. Have fun!!!

6 Likes
<script>
	var result = [];
	for (var i=1;i<=100;i++) {
		if (( i % 3 == 0 ) && (i % 5 == 0 )) {
			result.push("FizzBuzz");
		}
		else if ( i % 3 == 0 ) {
			result.push("Fizz");	
		}
		else if ( i % 5 == 0 ) {
			result.push("Buzz");	
		}		
		else {
		result.push(i);
	    }
}
	window.AppInventor.setWebViewString(JSON.stringify(result));
</script>

image

5 Likes

You and your son's versions look suspiciously similar...
I'm not nitpicking, though :wink:

3 Likes

Could you make your version complete with all app inventor blocks also? :grin:

1 Like

He adapted my version into something a software developer would make. He makes a living from it for me it is just a hobby. It was fun discussing good programming with him. :grin:

4 Likes

Done :slight_smile: :christmas_tree:

3 Likes

I tried the following:

It is somehow similar to yours (I didn't cheat!)

2 Likes

My solution

4 Likes

using python

one_to_hundred = []
for i in range(100):
    one_to_hundred.append(i)

for i in one_to_hundred:

    if i % 5 == 0 and i % 3 == 0:
        one_to_hundred[int(one_to_hundred.index(i))] = "FizzBuzz"

    if i % 3 == 0:
        if i % 5 == 0 and i % 3 == 0:
            pass
        else:
            one_to_hundred[int(one_to_hundred.index(i))] = "Fizz"

    if i % 5 == 0:
        if i % 5 == 0 and i % 3 == 0:
            pass
        else:
            one_to_hundred[int(one_to_hundred.index(i))] = "Buzz"

print(one_to_hundred)

just swipe towards left to see the full results in companion

FizzBuzz.aia (156.0 KB)

5 Likes

Can we do this outside appinventor as well?

The result needs to be generated and returned inside an AppInventor app

4 Likes

Oh ok Now I get it!

i think shorter isn't possible with blocks.

1 Like

fizz buzz its a javascript converter or something like that?.
where is the aix converter?. or skulpt aix?

See

for an explanation of what FizzBuzz is.