Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 63 additions & 16 deletions 5-advanced-JS/starter/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');