Forum Moderators: open

Message Too Old, No Replies

What's wrong with this function?

         

adni18

1:31 pm on Nov 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a string, called coordlist. It is empty (coordlist=""). If the string is empty at the time, I would like for it to make coordlist = b(an arguement). If there is already a number there, then make the string coordlist+"-"+b. I can run this the first time, but the second time, I get an error message.

function addCoord(b)
{
if(coordlist.split("-").length==1){coordlist=b;}
else if(coordlist.split("-").length==2){coordlist=coordlist+"-"+b;}
else if(coordlist.split("-").length==3){coordlist=b}
alert(coordlist);
}

Bernard Marx

2:47 pm on Nov 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't get any errors, what kind of inputs are you putting in?
(PS - try using a
switch/case
for simplicity)