Skip to content

Instantly share code, notes, and snippets.

@Just-Hosam
Forked from NimaBoscarino/lunch.js
Last active February 1, 2021 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Just-Hosam/42c703e609d64a27abfbe1db675de97f to your computer and use it in GitHub Desktop.
Save Just-Hosam/42c703e609d64a27abfbe1db675de97f to your computer and use it in GitHub Desktop.
W1D1 - What to do for Lunch?
/*
* Modify the contents of the function below, such that:
*
* If we're not hungry, we want to tell ourselves to get back to work.
* Otherwise, we want to pick something up and eat it in the lab when
* we've got less than 20 minutes or to try a place nearby if we've
* got between 20 and 30 minutes. If we have any more time than that,
* we want to remind ourselves that we're in a bootcamp and that we
* should reconsider how much time we actually have to spare.
*
* hungry is a Boolean, representing if you're hungry or not.
* availableTime is a Number representing the time you have for lunch,
* in minutes.
*/
const whatToDoForLunch = function(hungry, availableTime) {
console.log("I don't know what to do!");
if (!hungry) {
console.log(`Get back to work!`);
} else if (hungry && availableTime < 20) {
console.log(`Pick something up and eat it in the lab.`);
} else if (hungry && availableTime >= 20 && availableTime <= 30) {
console.log(`Try a place nearby.`);
} else if (hungry && availableTime > 30) {
console.log(`You're in a bootcamp... Be realistic.`);
} else {
console.log('fail');
}
};
/*
* This is some test runner code that's simply calling our whatToDoForLunch function
* defined above to verify we're making the right decisions. Do not modify it!
*/
console.log("I'm hungry and I have 20 minutes for lunch.");
whatToDoForLunch(true, 20);
console.log("---");
console.log("I'm hungry and I have 50 minutes for lunch.");
whatToDoForLunch(true, 50);
console.log("---");
console.log("I'm not hungry and I have 30 minutes for lunch.");
whatToDoForLunch(false, 30);
console.log("---");
console.log("I'm hungry and I have 15 minutes for lunch.");
whatToDoForLunch(true, 15);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment