File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Closure</ title >
7+ </ head >
8+ < body style = "background-color: #313131; ">
9+ < button id = "orange "> Orange</ button >
10+ < button id = "green "> Green</ button >
11+
12+ </ body >
13+ < script >
14+ // function init(){
15+ // let name = "Mozilla";
16+ // function displayName(){
17+ // console.log(name);
18+ // }
19+ // displayName();
20+ // }
21+ // init();
22+ // function outer(){
23+ // let username = "knnhhh"
24+ // function inner(){
25+ // let secret = "my123"
26+ // console.log("inner",username);
27+ // }
28+ // function innerTwo(){
29+ // console.log("innerTwo",username);
30+ // //console.log(secret);//No
31+ // }
32+ // inner()
33+ // }
34+ // outer()
35+ // console.log("Too Outer", username);//ERROr
36+
37+ // function makeFunc(){
38+ // const name = "Moxilla"
39+ // function displayName(){
40+ // console.log(name);
41+ // }
42+ // return displayName;
43+ // }
44+ // const myFunc = makeFunc();
45+ // myFunc();
46+
47+ // document.getElementById("orange").onclick = function(){
48+ // document.body.style.backgroundColor = `orange`
49+ // }
50+ // document.getElementById("green").onclick = function(){
51+ // document.body.style.backgroundColor = `green`
52+ // }
53+ //OR
54+
55+ function clickHandler ( color ) {
56+ return function ( ) {
57+ document . body . style . backgroundColor = `${ color } `
58+ }
59+ }
60+ document . getElementById ( "orange" ) . onclick = clickHandler ( "orange" )
61+ document . getElementById ( "green" ) . onclick = clickHandler ( "green" )
62+ </ script >
63+ </ html >
You can’t perform that action at this time.
0 commit comments