Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #32501
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2017-02-06 11:06 -0800 |
| References | <6cb902b0-8913-4b65-954d-5d9f0e60ee95@googlegroups.com> <lyrqf45qcj5e$.1n5qtbbdcd9n1.dlg@40tude.net> <XnsA714A2E97D7F5eejj99@194.109.6.166> |
| Message-ID | <ba300019-ca9d-4bb2-ab15-4925de51efa2@googlegroups.com> (permalink) |
| Subject | Re: setInterval |
| From | jonas.thornvall@gmail.com |
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.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web