diff --git a/5-advanced-JS/starter/script.js b/5-advanced-JS/starter/script.js index 58cd78ca1f..4bffb5671c 100755 --- a/5-advanced-JS/starter/script.js +++ b/5-advanced-JS/starter/script.js @@ -116,27 +116,74 @@ // console.log(rates); //Functions returning another function +// function interviewQuestion(job){ +// if (job === 'designer') { +// return function(name) { +// console.log(name, ', Can you please explain what UX design is?') +// } +// } else if(job === 'teacher') { +// return function(name){ +// console.log('what subject do you teach', name); +// } +// } else { +// return function(name) { +// console.log('Hello', name, 'what do you do?'); +// } +// } +// } + +// var teacherQuestion = interviewQuestion('teacher'); +// var designerQuestion = interviewQuestion('designer'); + +// teacherQuestion('John'); +// designerQuestion('Jane'); + +// interviewQuestion('teacher')('Mark'); + +//IIFE +//Immediatlt Invoked Function + +// function game() { +// var score = Math.random() * 10; +// console.log(score >= 5); + +// } +// game(); + +// (function(goodluck){ +// var score = Math.random() * 10; +// console.log(score >= 5 - goodluck); +// })(5); + +//Closures +function retirement(retirementAge) { + var a = ' years left until retirement'; + return function(yearOfBirth){ + var age = 2016 - yearOfBirth; + console.log((retirementAge - age) + a); + } +} + +var retirementUS = retirement(66); +var retirementDE = retirement(65); +var retirementIceland = retirement(67); + +retirementUS(1990); +retirementDE(1990); +retirementIceland(1990); + function interviewQuestion(job){ - if (job === 'designer') { - return function(name) { + return function(name){ + if(job === 'designer') { console.log(name, ', Can you please explain what UX design is?') - } - } else if(job === 'teacher') { - return function(name){ + } else if(job === 'teacher') { console.log('what subject do you teach', name); - } - } else { - return function(name) { + } else { console.log('Hello', name, 'what do you do?'); } } } -var teacherQuestion = interviewQuestion('teacher'); -var designerQuestion = interviewQuestion('designer'); - -teacherQuestion('John'); -designerQuestion('Jane'); - -interviewQuestion('teacher')('Mark'); - +interviewQuestion('designer')('John'); +interviewQuestion('teacher')('Jane'); +interviewQuestion('drug dealer')('Mark'); \ No newline at end of file