# Problem with wrapping a basic function

I'm working my way through Mathematica Challenges and tripped myself up on the first question. I have a basic piece of code which works, but am having trouble formatting it to be a proper written function. In searching for an answer myself, people online have made all sorts of shorter elegant solutions for this popular programming problem but my question is far simpler in that I don't know why my function is failing when I try to write it.

The working code I have:

 If[Mod[#,3]==Mod[#,5]==0,"fizzbuzz",
If[Mod[#,3]==0,"fizz",
If[Mod[#,5]==0,"buzz",#]]] &/@ Range


Wrapped into the function fizzbuzz:

 fizzbuzz[n_Integer]:= Module[{n},
If[Mod[#,3]==Mod[#,5]==0,"fizzbuzz",
If[Mod[#,3]==0,"fizz",
If[Mod[#,5]==0,"buzz",#]]] &/@ Range[n]]


But fizzbuzz just fails with no error given.

• Syntax coloring should have clued you in to the issue. You can’t use n as both an argument and a module variable – Carl Woll Dec 19 '17 at 3:32

You don't need Module[]

fizzbuzz[n_Integer] :=
If[Mod[#, 3] == Mod[#, 5] == 0, "fizzbuzz",
If[Mod[#, 3] == 0, "fizz", If[Mod[#, 5] == 0, "buzz", #]]] & /@
Range[n]


The following provides the test:

fizzbuzz == (If[Mod[#, 3] == Mod[#, 5] == 0, "fizzbuzz",
If[Mod[#, 3] == 0, "fizz", If[Mod[#, 5] == 0, "buzz", #]]] & /@
Range)


returning: True

• I had actually tried it without module initially. Trying your code in a new notebook worked. It might have been a quirk in MMA Online but it least it looks like I was doing it correctly. Thanks for the help. – BBirdsell Dec 19 '17 at 4:16