Switch to full style
HTML,DHTML,Javascript,XML,CSS
Post a reply

Java script time parameter

Sat Nov 10, 2012 12:23 am

I was wondering if any one knew how to make my code on math questions so that it would stop after a certain amount of time. For instance the user keeps on having questions asked until 30 seconds pass by.
Code:
//this is my function for random numbers//
var random = function(least,most){
return Math.floor(Math.random()*most + least);
};
//end of function//
var c;
var score=0;
confirm("New game");
console.log("new game");
var added = "";
for(c=1;c<=10;c++){
var num1=random(1,10);
var num2=random(1,10);
if(parseInt(prompt(added +"What is"+num1+"+"+num2+"?"))===(num1+num2)){
   score++;
   added="corect. You have "+score+" points ";
}
else{
   added="wrong You have "+score+" points ";
}


**Note this is only in JS



Re: Java script time parameter

Sat Nov 10, 2012 12:47 pm

You can use setTimeout function to sleep the thread for some time :

i used it in this example
javascript-examples/image-slide-show-t7775.html

Re: Java script time parameter

Sat Nov 10, 2012 4:31 pm

I see that but how can you use the setTimeout function to make something stop after a certain amount of time?

Re: Java script time parameter

Sun Nov 11, 2012 3:19 pm

yes
U setTimeout it is like sleep function
setTimeout("imageSlider()", 2000);

u put the function u want to run and with time (For how long)

Post a reply
  Related Posts  to : Java script time parameter
 Passing arrays as function parameter in java     -  
 need help with java script in a pdf     -  
 How can I call a C program in a Shell Script from Java     -  
 How to create a file in java script using FireFox     -  
 Dynamic Frame-sets with java script protocols     -  
 How to get system time in java     -  
 Default Expire time for Session JAVA     -  
 Java Websphere Portal Developer Full-time position in IL     -  
 get url parameter     -  
 using parameter with name query     -  

Topic Tags

JavaScript Time