473,326 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Why the delay please?

Amy
Hi, I finished this script and for some reason there is a delay
every so often in the timing. Sometimes
it seems two take 2 seconds instead of 1.
Can anyone see anything that would slow it down? I sure can't see it.
Thank you very much, Amy <body onload="changelink()"><a href="#"
id="url"></a>

arr = new Array();
arr[0] = ["Link 1","http://www.google.com"];
arr[1] = ["Link 2","http://www.msn.com"];
arr[2] = ["Link 3","http://www.yahoo.com"];
arr[3] = ["Link 4","http://www.google.com"];
arr[4] = ["Link 5","http://www.msn.com"];
arr[5] = ["Link 6","http://www.yahoo.com"];
arr[6] = ["Link 7","http://www.msn.com"];
arr[7] = ["Link 8","http://www.google.com"];
arr[8] = ["Link 9","http://www.yahoo.com"];
arr[9] = ["Link 10","http://www.msn.com"];
arr[10] = ["Link 11","http://www.yahoo.com"];
arr[11] = ["Link 12","http://www.google.com"];
arr[12] = ["Link 13","http://www.msn.com"];
arr[13] = ["Link 14","http://www.yahoo.com"];
arr[14] = ["Link 15","http://www.google.com"];
counter = 0;

function changelink()
{
rand = Math.floor(Math.random()*arr.length);
document.getElementById("url").href = arr[rand][1];
document.getElementById("url").innerHTML = arr[rand][0];
counter++;

if (counter == arr.length)
counter = 0;
}

setInterval('changelink()', 1000);

Nov 7 '06 #1
17 1761
Lee
Amy said:
>
Hi, I finished this script and for some reason there is a delay
every so often in the timing. Sometimes
it seems two take 2 seconds instead of 1.
Can anyone see anything that would slow it down? I sure can't see it.
Thank you very much, Amy <body onload="changelink()"><a href="#"
id="url"></a>

arr = new Array();
arr[0] = ["Link 1","http://www.google.com"];
arr[1] = ["Link 2","http://www.msn.com"];
arr[2] = ["Link 3","http://www.yahoo.com"];
arr[3] = ["Link 4","http://www.google.com"];
arr[4] = ["Link 5","http://www.msn.com"];
arr[5] = ["Link 6","http://www.yahoo.com"];
arr[6] = ["Link 7","http://www.msn.com"];
arr[7] = ["Link 8","http://www.google.com"];
arr[8] = ["Link 9","http://www.yahoo.com"];
arr[9] = ["Link 10","http://www.msn.com"];
arr[10] = ["Link 11","http://www.yahoo.com"];
arr[11] = ["Link 12","http://www.google.com"];
arr[12] = ["Link 13","http://www.msn.com"];
arr[13] = ["Link 14","http://www.yahoo.com"];
arr[14] = ["Link 15","http://www.google.com"];
counter = 0;

function changelink()
{
rand = Math.floor(Math.random()*arr.length);
document.getElementById("url").href = arr[rand][1];
document.getElementById("url").innerHTML = arr[rand][0];
counter++;

if (counter == arr.length)
counter = 0;
}

setInterval('changelink()', 1000);
Sometimes your computer is busy doing something else.
Can you explain the purpose of the "counter" variable?
This still looks like a homework assignment, to me.
--

Nov 7 '06 #2

Amy wrote:
Hi, I finished this script and for some reason there is a delay
every so often in the timing. Sometimes
it seems two take 2 seconds instead of 1.
Can anyone see anything that would slow it down? I sure can't see it.
arr = new Array();
arr[0] = ["Link 1","http://www.google.com"];
arr[1] = ["Link 2","http://www.msn.com"];
arr[2] = ["Link 3","http://www.yahoo.com"];
arr[3] = ["Link 4","http://www.google.com"];
arr[4] = ["Link 5","http://www.msn.com"];
arr[5] = ["Link 6","http://www.yahoo.com"];
arr[6] = ["Link 7","http://www.msn.com"];
arr[7] = ["Link 8","http://www.google.com"];
arr[8] = ["Link 9","http://www.yahoo.com"];
arr[9] = ["Link 10","http://www.msn.com"];
arr[10] = ["Link 11","http://www.yahoo.com"];
arr[11] = ["Link 12","http://www.google.com"];
arr[12] = ["Link 13","http://www.msn.com"];
arr[13] = ["Link 14","http://www.yahoo.com"];
arr[14] = ["Link 15","http://www.google.com"];
Think about it - what happens if we are displaying the content of
arr[0] and we pick the random number 3 as the next one to display?
Would the script appear to pause?

Nov 7 '06 #3

n...@chthonic.f9.co.uk wrote:
>
Think about it - what happens if we are displaying the content of
arr[0] and we pick the random number 3 as the next one to display?
Would the script appear to pause?
Scratch that - I meant if we pick the random number 0 as the next one
to display.

You can work out for yourself what to do next...

Nov 7 '06 #4
Lee
Amy said:
>
Hi, I finished this script and for some reason there is a delay
every so often in the timing. Sometimes
it seems two take 2 seconds instead of 1.
Can anyone see anything that would slow it down? I sure can't see it.
Thank you very much, Amy <body onload="changelink()"><a href="#"
id="url"></a>

arr = new Array();
arr[0] = ["Link 1","http://www.google.com"];
arr[1] = ["Link 2","http://www.msn.com"];
arr[2] = ["Link 3","http://www.yahoo.com"];
arr[3] = ["Link 4","http://www.google.com"];
arr[4] = ["Link 5","http://www.msn.com"];
arr[5] = ["Link 6","http://www.yahoo.com"];
arr[6] = ["Link 7","http://www.msn.com"];
arr[7] = ["Link 8","http://www.google.com"];
arr[8] = ["Link 9","http://www.yahoo.com"];
arr[9] = ["Link 10","http://www.msn.com"];
arr[10] = ["Link 11","http://www.yahoo.com"];
arr[11] = ["Link 12","http://www.google.com"];
arr[12] = ["Link 13","http://www.msn.com"];
arr[13] = ["Link 14","http://www.yahoo.com"];
arr[14] = ["Link 15","http://www.google.com"];
counter = 0;

function changelink()
{
rand = Math.floor(Math.random()*arr.length);
alert(rand);
>document.getElementById("url").href = arr[rand][1];
document.getElementById("url").innerHTML = arr[rand][0];
counter++;

if (counter == arr.length)
counter = 0;
}

setInterval('changelink()', 1000);
Even if this is an assignment, I suppose it doesn't hurt to
show you how to debug it. Add the alert() above and watch
how the values change. You'll see it more quickly if you
reduce the number of elements in arr while testing.
--

Nov 7 '06 #5
Amy
Thank you very much. This isn't homework at all, I provide all the
javascript almost completely done which is more than most people do.
You guys already seem to know what to do. I still don't know what your
trying to tell me. Can't seem to find that alert you told me to try.
Are you trying to tell me that with random arrays since its random it
takes longer sometimes to pick its next choice? Thats what causes a
delay? If thats the case why don't I have problem with other second
random arrays that I have tested? I'll slow down the timer and see what
happens and let you know. If there is something else I am messing
please tell me what it is.

Lee wrote:
Amy said:

Hi, I finished this script and for some reason there is a delay
every so often in the timing. Sometimes
it seems two take 2 seconds instead of 1.
Can anyone see anything that would slow it down? I sure can't see it.
Thank you very much, Amy <body onload="changelink()"><a href="#"
id="url"></a>

arr = new Array();
arr[0] = ["Link 1","http://www.google.com"];
arr[1] = ["Link 2","http://www.msn.com"];
arr[2] = ["Link 3","http://www.yahoo.com"];
arr[3] = ["Link 4","http://www.google.com"];
arr[4] = ["Link 5","http://www.msn.com"];
arr[5] = ["Link 6","http://www.yahoo.com"];
arr[6] = ["Link 7","http://www.msn.com"];
arr[7] = ["Link 8","http://www.google.com"];
arr[8] = ["Link 9","http://www.yahoo.com"];
arr[9] = ["Link 10","http://www.msn.com"];
arr[10] = ["Link 11","http://www.yahoo.com"];
arr[11] = ["Link 12","http://www.google.com"];
arr[12] = ["Link 13","http://www.msn.com"];
arr[13] = ["Link 14","http://www.yahoo.com"];
arr[14] = ["Link 15","http://www.google.com"];
counter = 0;

function changelink()
{
rand = Math.floor(Math.random()*arr.length);
alert(rand);
document.getElementById("url").href = arr[rand][1];
document.getElementById("url").innerHTML = arr[rand][0];
counter++;

if (counter == arr.length)
counter = 0;
}

setInterval('changelink()', 1000);

Even if this is an assignment, I suppose it doesn't hurt to
show you how to debug it. Add the alert() above and watch
how the values change. You'll see it more quickly if you
reduce the number of elements in arr while testing.
--
Nov 7 '06 #6
Amy
Are you trying to tell me I don't need the counter variable since its
random?

Making it a longer timer didn't help, it doubles the timing on some
items no matter what.

Nov 7 '06 #7
Amy
Don't know if thats what you are trying to tell me or not but makes
perfect sense so I took all the counters out. To this.

function changelink()
{
var rand = Math.floor(Math.random()*content.length);
document.getElementById("url").href = content[rand][1];
document.getElementById("url").innerHTML = content[rand][0];
}

setInterval("changelink()", 2000);

Same problem though, still a delay. I sure hope someone can help.

Nov 7 '06 #8
Lee
Amy said:
>
Thank you very much. This isn't homework at all, I provide all the
javascript almost completely done which is more than most people do.
You guys already seem to know what to do. I still don't know what your
trying to tell me. Can't seem to find that alert you told me to try.
Are you trying to tell me that with random arrays since its random it
takes longer sometimes to pick its next choice? Thats what causes a
delay? If thats the case why don't I have problem with other second
random arrays that I have tested? I'll slow down the timer and see what
happens and let you know. If there is something else I am messing
please tell me what it is.
If the same random number is generated twice in a row, the
link won't change, and so it will appear to be taking longer.
The following includes simple code to ensure that there are
no repeats by incrementing the value if necessary. You could
just create random numbers until you find one that's not the
same as the previous one, but this way has the advantage that
it even works if arr.length=1. We sacrifice some randomness
for that, but it's a good bargain in this case. Another way
to go would be to generate a shuffled list of indices and
iterating through it, so you never see a repeat until you've
seen all of the links, but that's more complicated.
You'll find more than you probably want to know at:
http://www.merlyn.demon.co.uk/js-randm.htm
var previous=-1;
function changelink() {
var rand = Math.floor(Math.random()*arr.length);
if ( rand == previous ) {
rand++;
if ( rand == arr.length ) {
rand=0;
}
}
previous=rand;
document.getElementById("url").href = arr[rand][1];
document.getElementById("url").innerHTML = arr[rand][0];
}
--

Nov 7 '06 #9
Amy wrote on 07 nov 2006 in comp.lang.javascript:
Don't know if thats what you are trying to tell me or not but makes
perfect sense so I took all the counters out. To this.
What are you talking about, Amy?

Could you please adhere to usenet netiquette and quote what you are
reacting on, as this is not email but usenet posting.

[and when you quote, please do not toppost]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Nov 7 '06 #10
Amy
Thank you very, very much Lee for the help, I'm trying it right now.

Evertjan, you tell me that I should do this and that, like I am doing
something hugely wrong. In my opinion you need to relax instead. All I
was doing was replying to all of your suggestions, that were one right
after the other and easy to track. There aren't so many posts in this
thread that there is a lot of confusion. Many of us in this life try
not to sweat this kind of small stuff that some get so picky about in
forums, and worry about much bigger concerns instead. Please don't try
pull me into conflicts over such tiny issues. Also, you can tell people
in much nicer ways without the edge. Regarding top posting, I think you
mean not replying to the very last post, I didn't know I was doing
that. But I'll keep an eye on it in case I am.
Could you please adhere to usenet netiquette and quote what you are
reacting on, as this is not email but usenet posting.>
[and when you quote, please do not toppost]
Nov 7 '06 #11
Amy wrote on 07 nov 2006 in comp.lang.javascript:
Thank you very, very much Lee for the help, I'm trying it right now.

Evertjan, you tell me that I should do this and that, like I am doing
something hugely wrong. In my opinion you need to relax instead. All I
was doing was replying to all of your suggestions, that were one right
after the other and easy to track. There aren't so many posts in this
thread that there is a lot of confusion. Many of us in this life try
not to sweat this kind of small stuff that some get so picky about in
forums, and worry about much bigger concerns instead. Please don't try
pull me into conflicts over such tiny issues. Also, you can tell people
in much nicer ways without the edge. Regarding top posting, I think you
mean not replying to the very last post, I didn't know I was doing
that. But I'll keep an eye on it in case I am.
>Could you please adhere to usenet netiquette and quote what you are
reacting on, as this is not email but usenet posting.>
[and when you quote, please do not toppost]
[Please do not toppost on usenet]

What a long reply for saying "thank you for allerting me to the habits of
usenet".

No, the quirks of usenet make it impossible to know that all prior postigs
have arrived or are still available on the specific newsserver of a
specific user. Thet's why those three mails without quoting are something
that should be pointed out to you.

No, having some order in a NG is not a trifle complared to some delay.

Should I be politer than saying please twice?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Nov 7 '06 #12
Amy
I guess I don't know what usenet is because I have no idea what your
talking about.
>From an average computer all these posts show up in the order they are
received, so if there is something I am missing you'll have to tell me
what it is. This is where we seem to still differ the most, your even
small critique on me was packed with edge. You could have told me a lot
nicer. Telling me I am using this as email etc. was all very mean.
People can use please in their posts but if it is also packed a lot of
sarcasm that totally cancels out "please."

Nov 7 '06 #13
Amy
I hope all that didn't chase you off Lee, I could still really use some
of your advise so I can try other things.

Its not working yet, I thought maybe because of that I should put the
"if" statements on the end, that didn't help. Is one "if" statement
supposed to be inside of the other?

Here's how it looks now. I am getting an error on the page with no
functions yet. Can anyone see what is wrong with this? Thanks a bunch.

var previous=-1;
function changelink() {
var rand = Math.floor(Math.random()*arr.length);
previous=rand;
document.getElementById("url").href = arr[rand][1];
document.getElementById("url").innerHTML = arr[rand][0];
if ( rand == previous ) {
rand++;
if ( rand == arr.length ) {
rand=0;
}
}
}

Nov 7 '06 #14
Lee
Amy said:
>
I hope all that didn't chase you off Lee, I could still really use some
of your advise so I can try other things.

Its not working yet, I thought maybe because of that I should put the
"if" statements on the end, that didn't help. Is one "if" statement
supposed to be inside of the other?
The function should look just like this:

function changelink() {
var rand = Math.floor(Math.random()*arr.length);
if ( rand == previous ) {
rand++;
if ( rand == arr.length ) {
rand=0;
}
}
previous=rand;
document.getElementById("url").href = arr[rand][1];
document.getElementById("url").innerHTML = arr[rand][0];
}

If you're getting errors from that, let us know what error
messages you're getting and post the exact code that caused
the errors.

By the way, "all these posts" are part of USENET. It's been
around much longer than Microsoft Windows or the World Wide Web,
and people use all sorts of different software to read the
messages, so we don't really know what you mean by how it looks
on an "average computer".

Notice how I include part of what you said in my response, and
then put my response at the bottom? That's what you're being
asked to do. People should be able to read any single message
and at least be able to decide if they're able to help. Ideally
they should have all the information they need.

You should also make sure you're responding to the correct
message. I almost didn't read this message from you because
it wasn't a response to my last message.

This newsgroup isn't a friendly place.
You'll have to get used to that.
--

Nov 7 '06 #15
Amy
At least Lee you're trying to be nice when telling me what I don't
understand. Thanks for the warning. I'm not here to try to make people
be nice, if they haven't figured that out all on their own thats their
loss in their life. I will tell someone if they are the ones to start
with an attitude first. I guess your telling me that usenet can't see
all these posts in the order they are given. I didn't know that and
will find out more about, thanks for telling me. I gave you all my code
including whats at the top of this post, its still the same. The error
message I am getting says "previous" is undefined.

Nov 7 '06 #16
Amy
Don't sweat it Lee some other nice person sent me something. Thanks for
trying to help.

Nov 7 '06 #17
In message <11**********************@m7g2000cwm.googlegroups. com>, Mon,
6 Nov 2006 18:44:00, Amy <ri*******@aol.comwrites
>Hi, I finished this script and for some reason there is a delay
every so often in the timing. Sometimes
it seems two take 2 seconds instead of 1.
Can anyone see anything that would slow it down? I sure can't see it.
Thank you very much, Amy <body onload="changelink()"><a href="#"
id="url"></a>

arr = new Array();
arr[0] = ["Link 1","http://www.google.com"];
arr[1] = ["Link 2","http://www.msn.com"];
...
arr[13] = ["Link 14","http://www.yahoo.com"];
arr[14] = ["Link 15","http://www.google.com"];
counter = 0;

function changelink()
{
rand = Math.floor(Math.random()*arr.length);
document.getElementById("url").href = arr[rand][1];
document.getElementById("url").innerHTML = arr[rand][0];
counter++;

if (counter == arr.length)
counter = 0;
}

setInterval('changelink()', 1000);
(A) With 15 entries in the array, on the average once in 15 times the
current entry will be picked next time.

(B) In some systems, setInterval('...', 1000); will fire at intervals
averaging slightly over one second - see FAQ section 3.2.
If your test system allows writing to window.status, include
window.status++ in changelink; it will show when your timer fires.

Check your articles before posting, and do not write "two" where "too"
is appropriate. If you are not a native English user, provide some
indication : those who do not are by default assumed to be American or
to deserve to be considered as such - and the dominant language there is
not unlike English.
In message <11********************@m7g2000cwm.googlegroups.co m>, Tue, 7
Nov 2006 11:14:03, Amy <ri*******@aol.comwrites
>
Evertjan, you tell me that I should do this and that, like I am doing
something hugely wrong.
That's because you are.

Being pig-headed is expected, but not mandatory, for Google Groups
users. Others have learned to avoid such faults. See St Luke: Chapter
10, Verse 37, tail.

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Nov 8 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Des L. Davis | last post by:
System: Dell PowerEdge Server with 3 GB RAM, 2.4 GHz Celeron Software: Microsoft SQL Server 2000 Enterprise running on Windows 2003 Server Software: Microsoft SQL Server 2000 Enterprise running on...
1
by: Troy | last post by:
Hello- I have a need to allow a user to reload a page on a chosen interval (selected from a select box) or to chose not to reload the page at all (default). I would like to do this in...
1
by: John Smith | last post by:
Hello! I have following developing environment: Visual Studio.NET 2003 ..NET Framework 1.1 local ASPNET account exists Windows XP Professional All worked perfectly for months.
6
by: adish11 | last post by:
Hi, In Web Application I would like to create delay for 30 sec in the code to enable external process to run. During the delay in application I would like to show the user message like "Please...
11
by: Maheshkumar.R | last post by:
Hi groups, How i can introduce some milliseconds delay in application. How i can do achieve this... let me clearly say... (1) I'm displaying slices of medical images. For framerate - for...
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I make a 10 second delay? ----------------------------------------------------------------------- There...
1
by: maul581 | last post by:
I know the delay( ) function of Turbo C and used it in my project. By this function we can give intermediate delay in execution from 1 millisecond to 9999 millisecond. My main question is "Is it...
1
by: maul581 | last post by:
I know the delay( ) function of Turbo C and used it in my project. By this function we can give intermediate delay in execution from 1 millisecond to 9999 millisecond. My main question is "Is it...
0
by: stirucherai | last post by:
Here is my what I am trying to do 1. Open a MP3 file (Sound) -- Multiple songs -- roughly 30 seconds per song 2. Dynamically create TEXT Field using CreateText method 3. Show Lyrics for the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.