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


Groups > comp.lang.javascript > #32521

Re: setInterval

Newsgroups comp.lang.javascript
Subject Re: setInterval
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References (1 earlier) <lyrqf45qcj5e$.1n5qtbbdcd9n1.dlg@40tude.net> <XnsA714A2E97D7F5eejj99@194.109.6.166> <ba300019-ca9d-4bb2-ab15-4925de51efa2@googlegroups.com> <XnsA714EB7013EE2eejj99@194.109.6.166> <8c587573-5c2d-4279-9d1f-c80dbf2b6e41@googlegroups.com>
Date 2017-02-06 23:41 +0100
Message-ID <XnsA714F1040F76Eeejj99@194.109.6.166> (permalink)

Show all headers | View raw


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)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


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