116116// console.log(rates);
117117
118118//Functions returning another function
119+ // function interviewQuestion(job){
120+ // if (job === 'designer') {
121+ // return function(name) {
122+ // console.log(name, ', Can you please explain what UX design is?')
123+ // }
124+ // } else if(job === 'teacher') {
125+ // return function(name){
126+ // console.log('what subject do you teach', name);
127+ // }
128+ // } else {
129+ // return function(name) {
130+ // console.log('Hello', name, 'what do you do?');
131+ // }
132+ // }
133+ // }
134+
135+ // var teacherQuestion = interviewQuestion('teacher');
136+ // var designerQuestion = interviewQuestion('designer');
137+
138+ // teacherQuestion('John');
139+ // designerQuestion('Jane');
140+
141+ // interviewQuestion('teacher')('Mark');
142+
143+ //IIFE
144+ //Immediatlt Invoked Function
145+
146+ // function game() {
147+ // var score = Math.random() * 10;
148+ // console.log(score >= 5);
149+
150+ // }
151+ // game();
152+
153+ // (function(goodluck){
154+ // var score = Math.random() * 10;
155+ // console.log(score >= 5 - goodluck);
156+ // })(5);
157+
158+ //Closures
159+ function retirement ( retirementAge ) {
160+ var a = ' years left until retirement' ;
161+ return function ( yearOfBirth ) {
162+ var age = 2016 - yearOfBirth ;
163+ console . log ( ( retirementAge - age ) + a ) ;
164+ }
165+ }
166+
167+ var retirementUS = retirement ( 66 ) ;
168+ var retirementDE = retirement ( 65 ) ;
169+ var retirementIceland = retirement ( 67 ) ;
170+
171+ retirementUS ( 1990 ) ;
172+ retirementDE ( 1990 ) ;
173+ retirementIceland ( 1990 ) ;
174+
119175function interviewQuestion ( job ) {
120- if ( job === 'designer' ) {
121- return function ( name ) {
176+ return function ( name ) {
177+ if ( job === 'designer' ) {
122178 console . log ( name , ', Can you please explain what UX design is?' )
123- }
124- } else if ( job === 'teacher' ) {
125- return function ( name ) {
179+ } else if ( job === 'teacher' ) {
126180 console . log ( 'what subject do you teach' , name ) ;
127- }
128- } else {
129- return function ( name ) {
181+ } else {
130182 console . log ( 'Hello' , name , 'what do you do?' ) ;
131183 }
132184 }
133185}
134186
135- var teacherQuestion = interviewQuestion ( 'teacher' ) ;
136- var designerQuestion = interviewQuestion ( 'designer' ) ;
137-
138- teacherQuestion ( 'John' ) ;
139- designerQuestion ( 'Jane' ) ;
140-
141- interviewQuestion ( 'teacher' ) ( 'Mark' ) ;
142-
187+ interviewQuestion ( 'designer' ) ( 'John' ) ;
188+ interviewQuestion ( 'teacher' ) ( 'Jane' ) ;
189+ interviewQuestion ( 'drug dealer' ) ( 'Mark' ) ;
0 commit comments