help with plotting a fourier series expansion in matlab!? please :)

I know its a lot so any little help at all is greatly appreciated! Thanks!

A square wave of period 2L is a step function which is equal to 1 for x from 0 to L, then is equal to -1 for x from L to 2L.
A square wave can be approximated by this Fourier Series expansion:
Infinity
(4/pi ) Σ(1/n) sin(n*pi*x/L)
n=1,3,5,.....etc
Write a program that:
1) prompts the user for a maximum valie for n and a value for L
Using those values, you will compute the Fourier Series expansion for a square wave and plot the result.
2) L must be a positive number, and n must be a positive odd integer.
3)If the user does not provide an acceptable number, you should detect the error, display an error message, and stop your script.
4)You should evaluate the function for 500 values of x, evenly distributed from 0 to 2L.

What I did so far is

input('enter a positive number for L')
input('enter a positive odd integer for n')
x=linspace(4*pi,500)
y=4/pi;
for
n=02*L)/(500-1):2*L;

y=(4/pi)*(1/n)*sin(n*pi*x/L);
end

plot(x,y)