Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #32484 > unrolled thread

setInterval

Started byjonas.thornvall@gmail.com
First post2017-02-05 23:26 -0800
Last post2017-02-06 23:41 +0100
Articles 6 on this page of 46 — 10 participants

Back to article view | Back to comp.lang.javascript


Contents

  setInterval jonas.thornvall@gmail.com - 2017-02-05 23:26 -0800
    Re: setInterval jonas.thornvall@gmail.com - 2017-02-05 23:30 -0800
      Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 00:17 -0800
        Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 00:24 -0800
          Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 00:36 -0800
            Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 01:10 -0800
              Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 01:20 -0800
                Re: setInterval Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-06 14:10 +0000
                  Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 11:25 -0800
                    Re: setInterval Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-06 21:12 +0000
                    Re: setInterval Silvio <silvio@internet.com> - 2017-02-06 22:15 +0100
                      Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 14:17 -0800
                        Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:50 +0100
                          Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 20:57 -0800
                            Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 21:15 -0800
                            Re: setInterval "Julio P. Di Egidio" <julio@diegidio.name> - 2017-02-07 06:22 +0100
                              Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 22:09 -0800
                                Re: setInterval Julio Di Egidio <julio@diegidio.name> - 2017-02-06 22:27 -0800
                                  Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 22:45 -0800
                                    Re: setInterval Jake Jarvis <pig_in_shoes@yahoo.com> - 2017-02-07 11:13 +0100
                              Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-07 17:23 +0100
                                Re: setInterval Julio Di Egidio <julio@diegidio.name> - 2017-02-07 11:54 -0800
                                  Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-07 21:54 +0100
                                    Re: setInterval Julio Di Egidio <julio@diegidio.name> - 2017-02-07 13:50 -0800
                                      Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-07 23:19 +0100
                                        Re: setInterval Julio Di Egidio <julio@diegidio.name> - 2017-02-07 15:33 -0800
                                          Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-09 00:23 +0100
                            Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-07 11:33 +0100
                      Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:28 +0100
                    Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:26 +0100
                  Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:24 +0100
                  Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-07 04:36 +0100
              Re: setInterval Silvio <silvio@internet.com> - 2017-02-06 16:13 +0100
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 12:10 -0800
                  Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 12:27 -0800
                    Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:16 +0100
                      Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 14:28 -0800
                        Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:45 +0100
                  Re: setInterval Tim Streater <timstreater@greenbee.net> - 2017-02-06 21:25 +0000
                    Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:19 +0100
    Re: setInterval JJ <jj4public@vfemail.net> - 2017-02-06 20:07 +0700
      Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 16:00 +0100
        Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 11:06 -0800
          Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:08 +0100
            Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 14:26 -0800
              Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:41 +0100

Page 3 of 3 — ← Prev page 1 2 [3]


#32493

FromJJ <jj4public@vfemail.net>
Date2017-02-06 20:07 +0700
Message-ID<lyrqf45qcj5e$.1n5qtbbdcd9n1.dlg@40tude.net>
In reply to#32484
On Sun, 5 Feb 2017 23:26:36 -0800 (PST), jonas.thornvall@gmail.com wrote:
> I find setInterval incredible confusing to use?
> Why does not mycount change?
> 
> function DEMO(){
>   mycount=50;
>   document.getElementById('mysubset').selectedIndex=1;
>   var interval_1 = setInterval("COUNTDOWN();",1000);
> }     
> 
> function COUNTDOWN(){
>   AUTOGRAPH();
>  document.NoLinks.linkval.value =mycount--;
>  if(mycount<1) clearInterval(interval_1);
> }

You've saved the timer interval ID into `interval_1` variable. But since
that variable is a local variable, it's disposed when `DEMO()` function
returns.

In `COUNTDOWN()` function, you're referring to a non existent `interval_1`
identifier.

[toc] | [prev] | [next] | [standalone]


#32495

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2017-02-06 16:00 +0100
Message-ID<XnsA714A2E97D7F5eejj99@194.109.6.166>
In reply to#32493
JJ <jj4public@vfemail.net> wrote on 06 Feb 2017 in comp.lang.javascript:

> On Sun, 5 Feb 2017 23:26:36 -0800 (PST), jonas.thornvall@gmail.com wrote:
>> I find setInterval incredible confusing to use?
>> Why does not mycount change?
>> 
>> function DEMO(){
>>   mycount=50;
>>   document.getElementById('mysubset').selectedIndex=1;
>>   var interval_1 = setInterval("COUNTDOWN();",1000);
>> }     
>> 
>> function COUNTDOWN(){
>>   AUTOGRAPH();
>>  document.NoLinks.linkval.value =mycount--;
>>  if(mycount<1) clearInterval(interval_1);
>> }
> 
> You've saved the timer interval ID into `interval_1` variable. But since
> that variable is a local variable, it's disposed when `DEMO()` function
> returns.
> 
> In `COUNTDOWN()` function, you're referring to a non existent `interval_1`
> identifier.

[Also mycount must be declared global] 

This works fine here:

<script type='text/javascript'> 'use strict'

var myInt;
let mycount = 20;
demo();

function demo() {
	myInt = setInterval(countdown, 300);
};

function countdown() {
	console.log(mycount);
	mycount--;
	if (mycount<1) clearInterval(myInt);
};

</script>

Simpler, imho, is:

<script type='text/javascript'> 'use strict'

let mycount = 20;
countdown();

function countdown() {
	console.log(mycount);
	if (--mycount) setTimeout(countdown, 300);
};

</script>



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#32501

Fromjonas.thornvall@gmail.com
Date2017-02-06 11:06 -0800
Message-ID<ba300019-ca9d-4bb2-ab15-4925de51efa2@googlegroups.com>
In reply to#32495
Den måndag 6 februari 2017 kl. 16:01:01 UTC+1 skrev Evertjan.:
> JJ <jj4public@vfemail.net> wrote on 06 Feb 2017 in comp.lang.javascript:
> 
> > On Sun, 5 Feb 2017 23:26:36 -0800 (PST), jonas.thornvall@gmail.com wrote:
> >> I find setInterval incredible confusing to use?
> >> Why does not mycount change?
> >> 
> >> function DEMO(){
> >>   mycount=50;
> >>   document.getElementById('mysubset').selectedIndex=1;
> >>   var interval_1 = setInterval("COUNTDOWN();",1000);
> >> }     
> >> 
> >> function COUNTDOWN(){
> >>   AUTOGRAPH();
> >>  document.NoLinks.linkval.value =mycount--;
> >>  if(mycount<1) clearInterval(interval_1);
> >> }
> > 
> > You've saved the timer interval ID into `interval_1` variable. But since
> > that variable is a local variable, it's disposed when `DEMO()` function
> > returns.
> > 
> > In `COUNTDOWN()` function, you're referring to a non existent `interval_1`
> > identifier.
> 
> [Also mycount must be declared global] 
> 
> This works fine here:
> 
> <script type='text/javascript'> 'use strict'
> 
> var myInt;
> let mycount = 20;
> demo();
> 
> function demo() {
> 	myInt = setInterval(countdown, 300);
> };
> 
> function countdown() {
> 	console.log(mycount);
> 	mycount--;
> 	if (mycount<1) clearInterval(myInt);
> };
> 
> </script>
> 
> Simpler, imho, is:
> 
> <script type='text/javascript'> 'use strict'
> 
> let mycount = 20;
> countdown();
> 
> function countdown() {
> 	console.log(mycount);
> 	if (--mycount) setTimeout(countdown, 300);
> };
> 
> </script>
> 
> 
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Maybe i do missunderstand how you advise me to do this, but it certainly does not seem to work for what i try to do.

See main.js

This is what i try to do but i fail clearInterval so the thread? keep running forever / until relaoded.

http://anybase.co.nf

Here i tried to adjust your code, and there is simply never any interval?

http://anybase.co.nf/GRAPH0.04/

Maybe i am incredible stupid but i fail to see the logic between the function calls it seem hidden behind some nonespoken logic layer. My guess is you guys just learn to do it, never reflect about the logic. I mean to set a timeout should be a nobrainer if your not incredible stupid, and i start to fear the worst, because i am simply unable to understand the logic behind it.

[toc] | [prev] | [next] | [standalone]


#32511

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2017-02-06 23:08 +0100
Message-ID<XnsA714EB7013EE2eejj99@194.109.6.166>
In reply to#32501
jonas.thornvall@gmail.com wrote on 06 Feb 2017 in comp.lang.javascript:

>> This works fine here:
>> 
>> <script type='text/javascript'> 'use strict'
>> 
>> var myInt;
>> let mycount = 20;
>> demo();
>> 
>> function demo() {
>>      myInt = setInterval(countdown, 300);
>> };
>> 
>> function countdown() {
>>      console.log(mycount);
>>      mycount--;
>>      if (mycount<1) clearInterval(myInt);
>> };
>> 
>> </script>
>> 
>> Simpler, imho, is:
>> 
>> <script type='text/javascript'> 'use strict'
>> 
>> let mycount = 20;
>> countdown();
>> 
>> function countdown() {
>>      console.log(mycount);
>>      if (--mycount) setTimeout(countdown, 300);
>> };
>> 
>> </script>
>> 
>> 
>> 
>> -- 
>> Evertjan.
>> The Netherlands.
>> (Please change the x'es to dots in my emailaddress)
> 
> Maybe i do missunderstand how you advise me to do this, but it certainly
> does not seem to work for what i try to do. 
> 
> See main.js

No I don't want to look, first try to understand the code i gave the above 
codes. It should work fine with you.
[Then you add one statement at a time of your code and debug where it goes 
wrong.]

> Maybe i am incredible stupid

I believe you, if you say so, why couldn't I?

This is not about credibility, but about building a code from what works 
fine to what you realy want it to do.

> but i fail to see the logic between the
> function calls it seem hidden behind some nonespoken logic layer. 

I don't undestand this sentence. 
What is anonespoken logic layer?
What function-calls?

=====================
The above code is just a single function:

>> function countdown() {
>>      console.log(mycount);
>>      if (--mycount) setTimeout(countdown, 300);
>> };

> My
> guess is you guys just learn to do it, never reflect about the logic.

Well, you guess wrong, the above function is strictly logical and is written  
so that it is completely understandable. 

It is just basic science 
[logic(2) based on basic facts(1), tested(3) to work]
where the basic facts are the specs of the javascript statements and 
functions.

> I
> mean to set a timeout should be a nobrainer if your not incredible
> stupid, 

So now someone else is stupid, me perhaps because you are in your own words?

> and i start to fear the worst, because i am simply unable to
> understand the logic behind it. 

Ah, why don't you ask for an explanation?

EXPLANATION:

let mycount = 20; // define variable globally ans det to 20  
countdown(); // call the recursive funtion 

function countdown() { // define recursive function
    	console.log(mycount); // write mycount to console
    	if (--mycount) // decrement mycount by one and do while result not zero
    	    	setTimeout(countdown, 300); // call itself after 300 milisecs
};

What don't you understand here???????????


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#32516

Fromjonas.thornvall@gmail.com
Date2017-02-06 14:26 -0800
Message-ID<8c587573-5c2d-4279-9d1f-c80dbf2b6e41@googlegroups.com>
In reply to#32511
Den måndag 6 februari 2017 kl. 23:08:46 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 06 Feb 2017 in comp.lang.javascript:
> 
> >> This works fine here:
> >> 
> >> <script type='text/javascript'> 'use strict'
> >> 
> >> var myInt;
> >> let mycount = 20;
> >> demo();
> >> 
> >> function demo() {
> >>      myInt = setInterval(countdown, 300);
> >> };
> >> 
> >> function countdown() {
> >>      console.log(mycount);
> >>      mycount--;
> >>      if (mycount<1) clearInterval(myInt);
> >> };
> >> 
> >> </script>
> >> 
> >> Simpler, imho, is:
> >> 
> >> <script type='text/javascript'> 'use strict'
> >> 
> >> let mycount = 20;
> >> countdown();
> >> 
> >> function countdown() {
> >>      console.log(mycount);
> >>      if (--mycount) setTimeout(countdown, 300);
> >> };
> >> 
> >> </script>
> >> 
> >> 
> >> 
> >> -- 
> >> Evertjan.
> >> The Netherlands.
> >> (Please change the x'es to dots in my emailaddress)
> > 
> > Maybe i do missunderstand how you advise me to do this, but it certainly
> > does not seem to work for what i try to do. 
> > 
> > See main.js
> 
> No I don't want to look, first try to understand the code i gave the above 
> codes. It should work fine with you.
> [Then you add one statement at a time of your code and debug where it goes 
> wrong.]
> 
> > Maybe i am incredible stupid
> 
> I believe you, if you say so, why couldn't I?
> 
> This is not about credibility, but about building a code from what works 
> fine to what you realy want it to do.
> 
> > but i fail to see the logic between the
> > function calls it seem hidden behind some nonespoken logic layer. 
> 
> I don't undestand this sentence. 
> What is anonespoken logic layer?
> What function-calls?
> 
> =====================
> The above code is just a single function:
> 
> >> function countdown() {
> >>      console.log(mycount);
> >>      if (--mycount) setTimeout(countdown, 300);
> >> };
> 
> > My
> > guess is you guys just learn to do it, never reflect about the logic.
> 
> Well, you guess wrong, the above function is strictly logical and is written  
> so that it is completely understandable. 
> 
> It is just basic science 
> [logic(2) based on basic facts(1), tested(3) to work]
> where the basic facts are the specs of the javascript statements and 
> functions.
> 
> > I
> > mean to set a timeout should be a nobrainer if your not incredible
> > stupid, 
> 
> So now someone else is stupid, me perhaps because you are in your own words?
> 
> > and i start to fear the worst, because i am simply unable to
> > understand the logic behind it. 
> 
> Ah, why don't you ask for an explanation?
> 
> EXPLANATION:
> 
> let mycount = 20; // define variable globally ans det to 20  
> countdown(); // call the recursive funtion 
> 
> function countdown() { // define recursive function
>     	console.log(mycount); // write mycount to console
>     	if (--mycount) // decrement mycount by one and do while result not zero
>     	    	setTimeout(countdown, 300); // call itself after 300 milisecs
> };
> 
> What don't you understand here???????????
> 
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Well Evertjan i not only do i decrease mycount i also make a call to a function that use in your case mycount as an imput parameter to do some drawing.

I figured i could replace your console.log printout with my function call. But it turn out that the function call never wait the setinterval. So when it finally show something mycase is already at min. So there is no animation drawn based on mycount, it has already stopped. I wanted it to wait for 300 ms before next call but it somehow manage to decrease the mycount before any thing is drawn and that i find weird. Because it work perfectly well clicking a button calling autograph going thru the animation. But here it just throw out the last state of mycount.

[toc] | [prev] | [next] | [standalone]


#32521

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2017-02-06 23:41 +0100
Message-ID<XnsA714F1040F76Eeejj99@194.109.6.166>
In reply to#32516
jonas.thornvall@gmail.com wrote on 06 Feb 2017 in comp.lang.javascript:

> Den måndag 6 februari 2017 kl. 23:08:46 UTC+1 skrev Evertjan.:
>> jonas.thornvall@gmail.com wrote on 06 Feb 2017 in comp.lang.javascript:
>> 
>> >> This works fine here:
>> >> 
>> >> <script type='text/javascript'> 'use strict'
>> >> 
>> >> var myInt;
>> >> let mycount = 20;
>> >> demo();
>> >> 
>> >> function demo() {
>> >>      myInt = setInterval(countdown, 300);
>> >> };
>> >> 
>> >> function countdown() {
>> >>      console.log(mycount);
>> >>      mycount--;
>> >>      if (mycount<1) clearInterval(myInt);
>> >> };
>> >> 
>> >> </script>
>> >> 
>> >> Simpler, imho, is:
>> >> 
>> >> <script type='text/javascript'> 'use strict'
>> >> 
>> >> let mycount = 20;
>> >> countdown();
>> >> 
>> >> function countdown() {
>> >>      console.log(mycount);
>> >>      if (--mycount) setTimeout(countdown, 300);
>> >> };
>> >> 
>> >> </script>
>> >> 
>> >> 
>> >> 
>> >> -- 
>> >> Evertjan.
>> >> The Netherlands.
>> >> (Please change the x'es to dots in my emailaddress)
>> > 
>> > Maybe i do missunderstand how you advise me to do this, but it
>> > certainl 
> y
>> > does not seem to work for what i try to do. 
>> > 
>> > See main.js
>> 
>> No I don't want to look, first try to understand the code i gave the
>> abov 
> e 
>> codes. It should work fine with you.
>> [Then you add one statement at a time of your code and debug where it
>> goe 
> s 
>> wrong.]
>> 
>> > Maybe i am incredible stupid
>> 
>> I believe you, if you say so, why couldn't I?
>> 
>> This is not about credibility, but about building a code from what
>> works 
>  
>> fine to what you realy want it to do.
>> 
>> > but i fail to see the logic between the
>> > function calls it seem hidden behind some nonespoken logic layer. 
>> 
>> I don't undestand this sentence. 
>> What is anonespoken logic layer?
>> What function-calls?
>> 
>> ====================
>> The above code is just a single function:
>> 
>> >> function countdown() {
>> >>      console.log(mycount);
>> >>      if (--mycount) setTimeout(countdown, 300);
>> >> };
>> 
>> > My
>> > guess is you guys just learn to do it, never reflect about the logic.
>> 
>> Well, you guess wrong, the above function is strictly logical and is
>> writ 
> ten  
>> so that it is completely understandable. 
>> 
>> It is just basic science 
>> [logic(2) based on basic facts(1), tested(3) to work]
>> where the basic facts are the specs of the javascript statements and 
>> functions.
>> 
>> > I
>> > mean to set a timeout should be a nobrainer if your not incredible
>> > stupid, 
>> 
>> So now someone else is stupid, me perhaps because you are in your own
>> wor 
> ds?
>> 
>> > and i start to fear the worst, because i am simply unable to
>> > understand the logic behind it. 
>> 
>> Ah, why don't you ask for an explanation?
>> 
>> EXPLANATION:
>> 
>> let mycount = 20; // define variable globally ans det to 20  
>> countdown(); // call the recursive funtion 
>> 
>> function countdown() { // define recursive function
>>          console.log(mycount); // write mycount to console
>>          if (--mycount) // decrement mycount by one and do while result
>>          not z 
> ero
>>                   setTimeout(countdown, 300); // call itself after 300
>>                   milisecs 
>> };
>> 
>> What don't you understand here???????????
> 
> Well Evertjan i not only do i decrease mycount i also make a call to a
> function that use in your case mycount as an imput parameter to do some
> drawing. 

Then you made a mistake in your code.

> I figured i could replace your console.log printout with my function
> call. 

Yes?

> But it turn out that the function call never wait the setinterval.

Of course, because there IS NO setinterval in MY code.

Listen to Silvio and do not patch code into your not working code,
but build up code frm our working examples.

> So when [..]

Not interested, first get your minimal working code together.



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [standalone]


Page 3 of 3 — ← Prev page 1 2 [3]

Back to top | Article view | comp.lang.javascript


csiph-web