Created
April 23, 2020 18:03
-
-
Save sandrabosk/50f24ccf8c5cf7b05c87035e392f66d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 1: What is the expected output? And why? | |
| function print() { | |
| console.log(1); | |
| setTimeout(() => console.log(2), 1000); | |
| setTimeout(() => console.log(3), 0); | |
| console.log(4); | |
| } | |
| print(); // => ??? | |
| // ------------------------------------------------------------------------ | |
| // 2: Use setTimeout() to print 'I am printing after ___ seconds.' | |
| // depending on how much delay is passed to setTimeout as delay. | |
| // Example: when calling printing(3) as a callback of setTimeout(), | |
| // it should print 'I am printing after 3 seconds.' when 3 seconds pass. | |
| // When calling printing(7) as a callback of setTimeout(), | |
| // it should print 'I am printing after 7 seconds.' when 7 seconds pass. | |
| function printing(delay) { | |
| // ... your code here | |
| } | |
| setTimeout(/* invoke printing here */); | |
| setTimeout(/* invoke printing here */); | |
| // ------------------------------------------------------------------------ | |
| //3: Countdown from 10 to 0. When the countdown is zero, it should show “Pop!” and stop the interval. | |
| let i = 10; | |
| const intervalId = setInterval(/* your code here */) | |
| // ------------------------------------------------------------------------ | |
| // BONUS: Write a script that prints 'Ironhack -> __ sec.' after every delay. | |
| // Example, if you start with the delay of 1 second, it should print 'Ironhack -> 1 sec.' | |
| // After that, the delay should be incremented by 1 second each time. | |
| // After 2 seconds, it should print 'Ironhack -> 2 sec.' | |
| // Then the delay should be 3 seconds, so after that time, it should print 'Ironhack -> 3 sec.' | |
| // And so on. | |
| function printIronhack(delay) { | |
| // ... your code here | |
| } | |
| printIronhack(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment