Skip to content

Instantly share code, notes, and snippets.

@ivalexandru
Created February 24, 2018 18:33
Show Gist options
  • Save ivalexandru/29ef2a12e2df3b09ff3e35e49086e5b1 to your computer and use it in GitHub Desktop.
Save ivalexandru/29ef2a12e2df3b09ff3e35e49086e5b1 to your computer and use it in GitHub Desktop.
//calc cati ani ai
function calculateAge(yearOfBirth) {
var age = 2016 - yearOfBirth;
return age;
}
var ageJohn = calculateAge(1990);
var ageMike = calculateAge(1969);
console.log(ageJohn);
//cat mai ai pana la pensie
//calling another function
function yearsUntilRetirement(name, year) {
var age = calculateAge(year);
var retirement = 65 - age;
//pui aici console.log ca sa nu mai pui pt fiecare persoana
if (retirement >= 0) {
console.log(name + ' retires in ' + retirement + ' years');
} else {
console.log( name + ' is already retired');
}
}
yearsUntilRetirement('John', 1990);
yearsUntilRetirement("Mary", 1948);
// in JS, functiile nu tre sa returneze neaparat ceva
//function statement just performs an action
//function expression PRODUCES A VALUE, an outcome
//var someFun = function(par) { //code } asta e function expression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment