Forum Moderators: open

Message Too Old, No Replies

The built in math methods are not define.

I am afraid I do not understand.

         

MarcMiller

11:14 am on Oct 5, 2005 (gmt 0)

10+ Year Member



Thanks for all the help I have gotten from this site so far. I fear I have another question yet. As I mind of mentioned I am working on a site that will change three images across the page choosing these images randomly and changing these images at somewhat random times. My JavaScript to accomplish this work still I add the somewhat random time aspect to it. I try to do this by using the math method like this. "500 + math.random()*1000" when this is in my code istead of 1000 my code stops working. And I get the Firefox JavaScript console error of "math is not defined" however I thought math methods will built into the JavaScript language so what is going on. Is there a proper way to use math methods in an improper way which I am doing. What's wrong. Code below.
Sincerely Marc

<HTML>
<HEAD>
<TITLE>coming</TITLE>
<SCRIPT TYPE="text/javascript">

var pr1= new Image();
pr1.src="images1.jpeg"

var pr2= new Image();
pr2.src="images2.jpeg"

var pr3= new Image();
pr3.src="images3.jpeg"

var pr4= new Image();
pr4.src="images4.jpeg"

var pr5= new Image();
pr5.src="images5.jpeg"

var pr6= new Image();
pr6.src="images6.jpeg"

var people=new Array( pr1.src, pr2.src, pr3.src, pr4.src, pr5.src, pr6.src);
function randomInteger(topInt)
{
return Math.round(Math.random()*topInt);

}
function chImage(builtInImageNum,arrayName,arrayNameNum)
{
document.images[builtInImageNum].src = arrayName[arrayNameNum];
}
var timeoutID0;
function repeatIntervalCh0(){
chImage(0,people,randomInteger(5));
timeoutID0 = setTimeout("repeatIntervalCh0()", 500 + math.random()*1000 );
}
var timeoutID1;
function repeatIntervalCh1(){
chImage(1,people,randomInteger(5));
timeoutID1 = setTimeout("repeatIntervalCh1()",1000);
}
var timeoutID2;
function repeatIntervalCh2(){
chImage(2,people,randomInteger(5));
timeoutID2 = setTimeout("repeatIntervalCh2()",1000);
}
function imageCh3()
{
chImage(0,people,randomInteger(5))
chImage(1,people,randomInteger(5))
chImage(2,people,randomInteger(5))
repeatIntervalCh0()
repeatIntervalCh1()
repeatIntervalCh2()
}
</SCRIPT>
</HEAD>

<BODY onload="imageCh3()" >
<div align="left"><IMG NAME = "chpeople1" SRC="images1.jpeg" BORDER="0" ALIGN="bottom" ALT="changing people"></div>
<div align="center"><IMG NAME = "chpeople2" SRC="images1.jpeg" BORDER="0" ALIGN="bottom" ALT="changing people"> </div>
<div align="right"><IMG NAME = "chpeople3" SRC="images1.jpeg" BORDER="0" ALIGN="bottom" ALT="changing people"> </div>
</BODY>
</HTML>

Bernard Marx

11:26 am on Oct 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's good fun to answer questions (mostly!), so have no fear of asking them.

math is not defined

Javascript is case-sensitive (you know that. Just reminding you!)

It's

[b]M[/b]ath

---------------------------------------------------------------------------

There is a little anomaly here. Javascript usually follows the Java convention, whereby initial capitals a only used for classes (object classes - unrelated to CSS). The nearest thing to classes in JS are constructor functions, so JS gives them initial caps (String, Number,...).

Math is not (meant to be) a constructor function. It's just an object that serves as a handy place to put all mathematical functions. It should, by convention, be lower case -but it isn't