Skip to content

Instantly share code, notes, and snippets.

@NimaBoscarino
Forked from kvirani/lunch.js
Last active September 16, 2024 04:29
Show Gist options
  • Save NimaBoscarino/068a5a51d2ee19604a00283af7deee4f to your computer and use it in GitHub Desktop.
Save NimaBoscarino/068a5a51d2ee19604a00283af7deee4f 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!");
}
/*
* 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);
@ianturner88
Copy link

const whatToDoForLunch = function(hungry, availableTime) {
if (hungry === false) {
console.log("Get back to work");
return "Get back to work";
} else if ((hungry === true) && (availableTime < 20)) {
console.log("Pick something up and eat in lab");
return "Pick something up and eat in lab";
} else if ((hungry === true) && (availableTime >=20) && (availableTime <=30)) {
console.log("Try a nearby place");
return "Try a nearby place";
} else {
return "Please reconsider how much free time you have!";
}
}

/*

  • 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