Skip to content

Instantly share code, notes, and snippets.

@garybunofsky
Created January 2, 2018 18:06
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 garybunofsky/e054e6aecbf9356d878180717a0a1afb to your computer and use it in GitHub Desktop.
Save garybunofsky/e054e6aecbf9356d878180717a0a1afb to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/laseyo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
}
</style>
</head>
<body>
<script id="jsbin-javascript">
var menu = [
{name: 'Waffles',
ingredients: ['flour', 'egg', 'yogurt', 'berries', 'honey syrup'],
available: true
},
{name: 'Eggs Benedict',
ingredients: ['egg', 'biscuit', 'hollandaise', 'bacon'],
available: false
},
{name: 'Toast',
ingredients: ['bread', 'jam'],
available: true
},
{name: 'Porridge',
ingredients: ['grains', 'water', 'milk', 'salt', 'sugar'],
available: true
},
{name: 'Toasted Baguette',
ingredients: ['bagguette', 'butter', 'jam'],
available: false
},
{name: 'Pan Cakes',
ingredients: ['flour', 'egg', 'syrup', 'butter'],
available: true
},
{name: 'Quiche',
ingredients: ['egg', 'spinach', 'salt', 'sugar', 'cheese'],
available: false
},
{name: 'Fruit Bowl',
ingredients: ['raspberry', 'pineapple', 'kiwi', 'blue berry', 'mango', 'pear'],
available: false
},
{name: 'Oatmeal',
ingredients: ['oats', 'milk', 'salt', 'sugar'],
available: true
}
];
// Answer 1
var itemCount = function(menuArray) {
return menuArray.length;
}
console.log('Answer 1: ', itemCount(menu));
// Answer 2
var availableItems = function(menuArray){
var available = [];
menuArray.forEach(function(item) {
if(item.available === true) {
available.push(item.name);
}
});
return available.sort();
}
console.log('Answer 2: ', availableItems(menu));
// Answer 3
var noCheese = function(menuArray) {
var itemsWithoutCheese = [];
menuArray.forEach(function(item) {
if (!item.ingredients.includes('cheese')) {
itemsWithoutCheese.push(item);
}
});
return itemsWithoutCheese;
}
console.log('Answer 3: ', noCheese(menu));
// Answer 4
var nowAvailable = function(itemName) {
menu.forEach(function(item){
if(item.name === itemName) {
item.available = true;
}
})
return menu;
}
console.log('Answer 4: ', nowAvailable('Eggs Benedict'));
// Answer 5
var noDairy = function(menuArray) {
var itemsWithoutDairy = [];
menuArray.forEach(function(item) {
if (!item.ingredients.includes('cheese') &&
!item.ingredients.includes('milk') &&
!item.ingredients.includes('butter') &&
!item.ingredients.includes('egg')) {
itemsWithoutDairy.push(item);
}
});
return itemsWithoutDairy;
}
console.log('Answer 5: ', noDairy(menu));
//
// Breakfast Time
//
// Congrats! You just acquired a restaurant. Now, let's format the menu.
// We have the variable menu which contains an array of objects. These
// objects contain data about our entrees.
//
// 1. Many guests want to know how many entrees we have. Write a reusable
// function called itemCount that will return the total number of items.
//
// 2. Our popular dishes often sell out before 10am. Write a function
// called availableItems returns a comma separated array of items
// that are available.(E.g: ['Waffles', 'Toast', 'Porridge', etc.])
//
// 2.1. Modify the availableItems function so the dishes are in
// alphabetical order.
//
// 3. Some of the restaurant guests are not fond of cheese. Write a
// reusable function called noCheese that will take one argument
// and return a new array of items that do not contain cheese.
//
// 4. Sometimes we take a trip to get the ingredients for dishes that
// are unavailable. When that happens we need to update our menu.
// Write a function called nowAvailable that takes the item name as an
// argument. This function should return an updated menu. It should use
// the argument to locate the item, then change the 'available' value
// to 'true'.
//
// 5. We found out that many patrons that avoid cheese also don't like
// butter, eggs or milk. Write a function called noDairy that only returns
// items that do not contain cheese, butter, eggs, or milk.
//
//
//
//
</script>
<script id="jsbin-source-css" type="text/css">
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">var menu = [
{name: 'Waffles',
ingredients: ['flour', 'egg', 'yogurt', 'berries', 'honey syrup'],
available: true
},
{name: 'Eggs Benedict',
ingredients: ['egg', 'biscuit', 'hollandaise', 'bacon'],
available: false
},
{name: 'Toast',
ingredients: ['bread', 'jam'],
available: true
},
{name: 'Porridge',
ingredients: ['grains', 'water', 'milk', 'salt', 'sugar'],
available: true
},
{name: 'Toasted Baguette',
ingredients: ['bagguette', 'butter', 'jam'],
available: false
},
{name: 'Pan Cakes',
ingredients: ['flour', 'egg', 'syrup', 'butter'],
available: true
},
{name: 'Quiche',
ingredients: ['egg', 'spinach', 'salt', 'sugar', 'cheese'],
available: false
},
{name: 'Fruit Bowl',
ingredients: ['raspberry', 'pineapple', 'kiwi', 'blue berry', 'mango', 'pear'],
available: false
},
{name: 'Oatmeal',
ingredients: ['oats', 'milk', 'salt', 'sugar'],
available: true
}
];
// Answer 1
var itemCount = function(menuArray) {
return menuArray.length;
}
console.log('Answer 1: ', itemCount(menu));
// Answer 2
var availableItems = function(menuArray){
var available = [];
menuArray.forEach(function(item) {
if(item.available === true) {
available.push(item.name);
}
});
return available.sort();
}
console.log('Answer 2: ', availableItems(menu));
// Answer 3
var noCheese = function(menuArray) {
var itemsWithoutCheese = [];
menuArray.forEach(function(item) {
if (!item.ingredients.includes('cheese')) {
itemsWithoutCheese.push(item);
}
});
return itemsWithoutCheese;
}
console.log('Answer 3: ', noCheese(menu));
// Answer 4
var nowAvailable = function(itemName) {
menu.forEach(function(item){
if(item.name === itemName) {
item.available = true;
}
})
return menu;
}
console.log('Answer 4: ', nowAvailable('Eggs Benedict'));
// Answer 5
var noDairy = function(menuArray) {
var itemsWithoutDairy = [];
menuArray.forEach(function(item) {
if (!item.ingredients.includes('cheese') &&
!item.ingredients.includes('milk') &&
!item.ingredients.includes('butter') &&
!item.ingredients.includes('egg')) {
itemsWithoutDairy.push(item);
}
});
return itemsWithoutDairy;
}
console.log('Answer 5: ', noDairy(menu));
//
// Breakfast Time
//
// Congrats! You just acquired a restaurant. Now, let's format the menu.
// We have the variable menu which contains an array of objects. These
// objects contain data about our entrees.
//
// 1. Many guests want to know how many entrees we have. Write a reusable
// function called itemCount that will return the total number of items.
//
// 2. Our popular dishes often sell out before 10am. Write a function
// called availableItems returns a comma separated array of items
// that are available.(E.g: ['Waffles', 'Toast', 'Porridge', etc.])
//
// 2.1. Modify the availableItems function so the dishes are in
// alphabetical order.
//
// 3. Some of the restaurant guests are not fond of cheese. Write a
// reusable function called noCheese that will take one argument
// and return a new array of items that do not contain cheese.
//
// 4. Sometimes we take a trip to get the ingredients for dishes that
// are unavailable. When that happens we need to update our menu.
// Write a function called nowAvailable that takes the item name as an
// argument. This function should return an updated menu. It should use
// the argument to locate the item, then change the 'available' value
// to 'true'.
//
// 5. We found out that many patrons that avoid cheese also don't like
// butter, eggs or milk. Write a function called noDairy that only returns
// items that do not contain cheese, butter, eggs, or milk.
//
//
//
//
</script></body>
</html>
var menu = [
{name: 'Waffles',
ingredients: ['flour', 'egg', 'yogurt', 'berries', 'honey syrup'],
available: true
},
{name: 'Eggs Benedict',
ingredients: ['egg', 'biscuit', 'hollandaise', 'bacon'],
available: false
},
{name: 'Toast',
ingredients: ['bread', 'jam'],
available: true
},
{name: 'Porridge',
ingredients: ['grains', 'water', 'milk', 'salt', 'sugar'],
available: true
},
{name: 'Toasted Baguette',
ingredients: ['bagguette', 'butter', 'jam'],
available: false
},
{name: 'Pan Cakes',
ingredients: ['flour', 'egg', 'syrup', 'butter'],
available: true
},
{name: 'Quiche',
ingredients: ['egg', 'spinach', 'salt', 'sugar', 'cheese'],
available: false
},
{name: 'Fruit Bowl',
ingredients: ['raspberry', 'pineapple', 'kiwi', 'blue berry', 'mango', 'pear'],
available: false
},
{name: 'Oatmeal',
ingredients: ['oats', 'milk', 'salt', 'sugar'],
available: true
}
];
// Answer 1
var itemCount = function(menuArray) {
return menuArray.length;
}
console.log('Answer 1: ', itemCount(menu));
// Answer 2
var availableItems = function(menuArray){
var available = [];
menuArray.forEach(function(item) {
if(item.available === true) {
available.push(item.name);
}
});
return available.sort();
}
console.log('Answer 2: ', availableItems(menu));
// Answer 3
var noCheese = function(menuArray) {
var itemsWithoutCheese = [];
menuArray.forEach(function(item) {
if (!item.ingredients.includes('cheese')) {
itemsWithoutCheese.push(item);
}
});
return itemsWithoutCheese;
}
console.log('Answer 3: ', noCheese(menu));
// Answer 4
var nowAvailable = function(itemName) {
menu.forEach(function(item){
if(item.name === itemName) {
item.available = true;
}
})
return menu;
}
console.log('Answer 4: ', nowAvailable('Eggs Benedict'));
// Answer 5
var noDairy = function(menuArray) {
var itemsWithoutDairy = [];
menuArray.forEach(function(item) {
if (!item.ingredients.includes('cheese') &&
!item.ingredients.includes('milk') &&
!item.ingredients.includes('butter') &&
!item.ingredients.includes('egg')) {
itemsWithoutDairy.push(item);
}
});
return itemsWithoutDairy;
}
console.log('Answer 5: ', noDairy(menu));
//
// Breakfast Time
//
// Congrats! You just acquired a restaurant. Now, let's format the menu.
// We have the variable menu which contains an array of objects. These
// objects contain data about our entrees.
//
// 1. Many guests want to know how many entrees we have. Write a reusable
// function called itemCount that will return the total number of items.
//
// 2. Our popular dishes often sell out before 10am. Write a function
// called availableItems returns a comma separated array of items
// that are available.(E.g: ['Waffles', 'Toast', 'Porridge', etc.])
//
// 2.1. Modify the availableItems function so the dishes are in
// alphabetical order.
//
// 3. Some of the restaurant guests are not fond of cheese. Write a
// reusable function called noCheese that will take one argument
// and return a new array of items that do not contain cheese.
//
// 4. Sometimes we take a trip to get the ingredients for dishes that
// are unavailable. When that happens we need to update our menu.
// Write a function called nowAvailable that takes the item name as an
// argument. This function should return an updated menu. It should use
// the argument to locate the item, then change the 'available' value
// to 'true'.
//
// 5. We found out that many patrons that avoid cheese also don't like
// butter, eggs or milk. Write a function called noDairy that only returns
// items that do not contain cheese, butter, eggs, or milk.
//
//
//
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment