Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hi, all. i'm new 2 js but im makin 2

Status
Not open for further replies.

iLy54

Programmer
Sep 5, 2002
33
ZA
hi, all. i'm new 2 js but im makin progress. my problem is that i hav an array that contains 10 numbers, like this:

var y=new Array(10,9,8,7,6,5,4,3,2,1,0)

my for loop displays each number consecutively starting from 10, like this:

{color red]function countDown(kk) {
window.status =y[kk];
if(kk !=y.length - 1) {
kk++; setTimeout("countDown(" + kk + ");", 1000);[/color]

i'm sure u can c what i'm doin with the script.
what i want 2do is be able 2 start at any number say 50 and end at 1 without having to put 50 numbers in the array.i'm hoping there is an easier way.
i would appreciate all the help you can give.
thanx
-Mon3y is the r00t of all evil and every man needs roots-
 
Why don't you do it this way :
Code:
function countDown(kk) {
    window.status = new String(kk);
    if(kk > 0)  {
       kk--;
       setTimeout("countDown(" + kk + ");", 1000);
    }
}
Note : you can use the setInterval Method to constantly run your timer instead of running it each call. see my FAQ : for more details. Water is not bad as long as it stays out human body ;-)
 
i'm not sure if i understand what is bein said.so how would i do what i want.
what i want is for a variable to be set like this:
var y=15;
and then i want first 15 and then 1second l8r 14 must be displayed and so on.once it reches 1 an alert must popup.
i've accomplished this by having an array that contains the numbers 15 thru to 1 and used the function above in my first post.
but mi problem is if i wanted 2start at a bigger number like 50 i dont want to have 2 write all the numbers from 50 thru to 1.
so i want to no if there's a way and i know there is.
i hope i clarifyed my question and as i'v said im new 2 js so i might not be very precise with my questions.
thanx so much! -Mon3y is the r00t of all evil and every man needs roots-
 
Why declare the variable like var y=15;?
You just need to call Targol's function with the number you want to start at as a parameter.
Example:
Code:
countDown(50);
Should work for you.
 
thanx Targol and HellTel for ur help.u both deserve a *.
i got it 2work perfectly -Mon3y is the r00t of all evil and every man needs roots-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top