Jump to content

JS anomaly.


Omirion

Recommended Posts

function test(myTrig,t){
var num = arguments.length
if (num == 0){
	alert("preset stage");
	setTimeout(function(){test(1,1)},2);
} if (myTrig == 1){
	alert("starting first recursion");
	if (t==1.5 || t>1.5) {
		alert("exiting"); 
		return ;
	}
	alert(myTrig);
	alert(t);
	t += 0.1;
	setTimeout(function(){test(1,t)},2);
} if (myTrig == 2){
	alert(myTrig);
}
}

 

When this function is run clean like so

test();

 

It passes trough a preset stage and then is passed on to the first recursive part of the code.

 if (myTrig == 1){
	alert("starting first recursion");
	if (t==1.5 || t>1.5) {
		alert("exiting"); 
		return ;
	}
	alert(myTrig);
	alert(t);
	t += 0.1;
	setTimeout(function(){test(1,t)},2);

 

Each time var t is incremented by 0.1.

But not exactly, a 0.000000001 value is also added.

 

 

Any JS magician care to explain?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.