Commit f82d6479 authored by MohammadAli Keshavarz's avatar MohammadAli Keshavarz

Function Statements and Expressions

parent 6a472c1f
......@@ -221,7 +221,7 @@ if (height === '23') {
/*****************************
* Functions
*/
/*
function calculateAge(birthYear) {
return 2018 - birthYear;
}
......@@ -243,4 +243,32 @@ function yearsUntilRetirement(year, firstName) {
yearsUntilRetirement(1990, 'John');
yearsUntilRetirement(1948, 'Mike');
yearsUntilRetirement(1969, 'Jane');
*/
/*****************************
* Function Statements and Expressions
*/
// Function declaration
// function whatDoYouDo(job, firstName) {}
// Function expression
var whatDoYouDo = function(job, firstName) {
switch(job) {
case 'teacher':
return firstName + ' teaches kids how to code';
case 'driver':
return firstName + ' drives a cab in Lisbon.'
case 'designer':
return firstName + ' designs beautiful websites';
default:
return firstName + ' does something else';
}
}
console.log(whatDoYouDo('teacher', 'John'));
console.log(whatDoYouDo('designer', 'Jane'));
console.log(whatDoYouDo('retired', 'Mark'));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment