-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback-example.js
More file actions
29 lines (25 loc) · 865 Bytes
/
callback-example.js
File metadata and controls
29 lines (25 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// callbacks, promises, async/await
const heading1 = document.querySelector(".heading-1");
const heading2 = document.querySelector(".heading-2");
const heading3 = document.querySelector(".heading-3");
const btn = document.querySelector(".btn");
/* Initial Example */
// btn.addEventListener("click", () => {
// console.log("You clicked the button.");
// });
// console.log("I'm second");
// for (let i = 0; i < 10000; i++) {
// console.log("I am busy");
// }
/* Second Example - The challenge here second one should start executing once first one completes and same goes for third to second*/
btn.addEventListener("click", () => {
setTimeout(() => {
heading1.style.color = "red";
setTimeout(() => {
heading2.style.color = "green";
setTimeout(() => {
heading3.style.color = "blue";
}, 1000);
}, 2000);
}, 1000);
});