Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
This javascript code i have doesnt seem to work. Im new to javascript and orignally tried to avoid it and learned php instead... shouldve just learned it...

JavaScript
var status;
var miles = 2000;
var togo = 2000;
var day = 1;
var interval;
//Miles, day, and togo are normally constantly changing.
function checkstatus(){
	if(miles == 2000){
		clearInterval(interval); //It doesnt even get here
                document.getElementById("status").innerHTML="Status: At the place!";
		alert("You've reached the place!!");
		}
        }

function wGo(){
	clearInterval(interval);
	document.getElementById("status").innerHTML="Status: Moving";
	interval = setInterval(function(){checkstatus();},5000);
}

Tried it on my browser my other browser and js fiddle and my mouse ends up blinking for a while.
Posted
Comments
Sergey Alexandrovich Kryukov 18-Nov-13 21:51pm    
This is of course not because "'if' is not working"... :-) It's a pretty bad idea to start your question with an apparently false statement.

You can execute this function under debugger and see what's going on. But the whole idea is quite bad. At least don't hard-code the constants, especially in two different places. Think what happens if you decide to change 2000 into something else.
If you explain your goal, we would probably help you...

—SA
G4mm4R4y 18-Nov-13 22:04pm    
I meant to reply, see comment below
G4mm4R4y 18-Nov-13 21:57pm    
The goal is to alert the user when his mileage goes up to 2000. It checks the mileage every 5 seconds. I thought this is the proper way to layout if statements?
ZurdoDev 18-Nov-13 22:01pm    
1. Reply to the comment so that the user is notified.
2. Where do you call it every 5 seconds?
3. Put a breakpoint on line 1 of checkstatus() and see what happens.
G4mm4R4y 18-Nov-13 22:03pm    
I thought I did reply, I apologize to Sergey and will reply. I can't check the code at the moment.

1 solution

Found it! Shouldve posted whole code but when i debugged it like earlier suggested it revealed a variable was undefined and for some reason it stalled my whole code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900