Click to See Complete Forum and Search --> : What the hey? Netscape sais that defined function is undefined but it works in IE.


iNerd
11-22-2003, 10:14 PM
I have a simple function that's called by other following functions but netscape sais that it's undefined though it works in IE and it even works if I paste it into the address bar.
function randInt(){
var a,t,f=isNaN(f=(a=randInt.arguments)[0])?0:f;
t=isNaN(t=a[1])?1:t;
return Math.round(Math.random()*(t-f)+f);
}
function genSomething(){
//....
var l=randInt(3,5); //<--This is line 186
//....
}

Netscape sais "line 186: randInt is undefined" and IE works it fine without error. Why?

ray326
11-23-2003, 01:02 PM
I see no indication that randInt() is a standard Javascript function but here's one that might work for you.

/* Generate a random number between low and high
eg. randint(2,5) will return 2, 3, 4, or 5 */

function randInt(low,high) {
return Math.floor(Math.random()*(high-low+1)+low);
}

iNerd
11-24-2003, 05:25 PM
Bah. You didn't read it right or something. I didn't say that randInt is a standard JS function, I defined it myself. I did it how I did so the arguments are optional, and it will assume from 0 to 1 { randInt(0,1); } if they are omitted. It is a properly written function, that's not the issue. If I take out the returns and copy and paste the function into the location bar in netscape followed by randInt(number,number) then it works fine. But it doesn't work when called by the function defined after it in the script. Why?