Commit 6a472c1f authored by MohammadAli Keshavarz's avatar MohammadAli Keshavarz

Functions

parent adb38bb1
...@@ -200,7 +200,7 @@ switch (true) { ...@@ -200,7 +200,7 @@ switch (true) {
/***************************** /*****************************
* Truthy and Falsy values and equality operators * Truthy and Falsy values and equality operators
*/ */
/*
// falsy values: undefined, null, 0, '', NaN // falsy values: undefined, null, 0, '', NaN
// truthy values: NOT falsy values // truthy values: NOT falsy values
var height; var height;
...@@ -214,4 +214,33 @@ if (height || height === 0) { ...@@ -214,4 +214,33 @@ if (height || height === 0) {
if (height === '23') { if (height === '23') {
console.log('The == operator does type coercion!'); console.log('The == operator does type coercion!');
} }
*/
/*****************************
* Functions
*/
function calculateAge(birthYear) {
return 2018 - birthYear;
}
var ageJohn = calculateAge(1990);
var ageMike = calculateAge(1948);
var ageJane = calculateAge(1969);
console.log(ageJohn, ageMike, ageJane);
function yearsUntilRetirement(year, firstName) {
var age = calculateAge(year);
var retirement = 65 - age;
if (retirement > 0) {
console.log(firstName + ' retires in ' + retirement + ' years.');
} else {
console.log(firstName + ' is already retired.')
}
}
yearsUntilRetirement(1990, 'John');
yearsUntilRetirement(1948, 'Mike');
yearsUntilRetirement(1969, 'Jane');
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