# How to define a function having many steps? [duplicate]

I can't transform a simple code into a function. The function should take an integer and return a list of digits in a factorial number system:

X=36177
j = 2; x = {}; While[X > 0, AppendTo[x, Mod[X, j]];
X = Quotient[X, j]; j++]; x


When I use

f[X_Integer] :=
Module[{j, x}, j = 2; x = {};
While[X > 0, AppendTo[x, Mod[X, j]]; X = Quotient[X, j]; j++]; x]


as is recommended I get next message:

Set::setraw: Cannot assign to raw object 36177. >>

Set::setraw: Cannot assign to raw object 36177. >>

Set::setraw: Cannot assign to raw object 36177. >>

General::stop: Further output of Set::setraw will be suppressed during this calculation. >>

f[X_Integer] :=Module[{j, x, xX}, j = 2; x = {}; xX = X;