finalCountdown.js 465 B

12345678910111213141516171819202122
  1. (function () {
  2. let counter = 0;
  3. const countdown = () => {
  4. let inner_timeout = setTimeout(countdown, 1000);
  5. if (counter === 5) {
  6. clearTimeout(inner_timeout);
  7. }
  8. console.log(counter === 5 ? console.log("поехали!") : 5 - counter);
  9. counter++
  10. }
  11. setTimeout(countdown, 1000);
  12. })();
  13. // или
  14. for (let i = 0; i <= 5; ++i) {
  15. setTimeout(() => {
  16. i === 5 ? console.log("поехали!") : console.log(5 - i);
  17. }, 1000 * i);
  18. }