Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save IacovColisnicenco/7770023a0f454b3a59d200478ed1c4e7 to your computer and use it in GitHub Desktop.
Save IacovColisnicenco/7770023a0f454b3a59d200478ed1c4e7 to your computer and use it in GitHub Desktop.
Замыкания в Javascript
const helloGuest = function(nameGuest) {
const dt = new Date();
const hour = dt.getHours();
return function(){
if(hour >= 0 && hour <6 ) {
console.log(`Good Night ${nameGuest}`);
}
else if (hour > 6 && hour < 12) {
console.log(`Good Morning ${nameGuest}`);
}
else if (hour > 12 && hour < 18) {
console.log(`Good Afternoon ${nameGuest}`);
}
else {
console.log(`Good Evening ${nameGuest}`);
}
};
};
const hello = helloGuest('Petea');
hello();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment