Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #32511
| Newsgroups | comp.lang.javascript |
|---|---|
| Subject | Re: setInterval |
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
| References | <6cb902b0-8913-4b65-954d-5d9f0e60ee95@googlegroups.com> <lyrqf45qcj5e$.1n5qtbbdcd9n1.dlg@40tude.net> <XnsA714A2E97D7F5eejj99@194.109.6.166> <ba300019-ca9d-4bb2-ab15-4925de51efa2@googlegroups.com> |
| Date | 2017-02-06 23:08 +0100 |
| Message-ID | <XnsA714EB7013EE2eejj99@194.109.6.166> (permalink) |
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)
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