Skip to content

Instantly share code, notes, and snippets.

@crhallberg
Last active June 14, 2023 16:53
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 crhallberg/af9f0b8b30753c63e5df4b16a5e7b271 to your computer and use it in GitHub Desktop.
Save crhallberg/af9f0b8b30753c63e5df4b16a5e7b271 to your computer and use it in GitHub Desktop.
Falvey 2023: Intro to Javascript
console.log("Hello, Falvey!!");
// JS will ignore this
let MULCH = 2;
let INCHES_IN_A_YARD = 36 * 36 * 36;
function doCalculations(garden) {
// We want 2 inches of mulch
garden.mulchDepth = MULCH;
garden.compostDepth = garden.fillDepth - MULCH;
// UNLESS we have 2 inches or less
if (garden.fillDepth <= MULCH) {
garden.mulchDepth = 1;
garden.compostDepth = garden.fillDepth - 1;
}
garden.mulchYards = garden.width * garden.length * garden.mulchDepth / INCHES_IN_A_YARD;
garden.compostYards = garden.width * garden.length * garden.compostDepth / INCHES_IN_A_YARD;
console.log("Mulch Volume", garden.mulchYards);
console.log("Compost Volume", garden.compostYards);
console.log();
return garden;
}
// Back Wall – Beans 19 32 2
let beanBed = {
name: "Bean Bed",
width: 19, // inches
length: 32, // inches
fillDepth: 2, // inches
};
// Box 1 – Tomatoes 57 137 5
let tomatoBox = {
name: "Tomato Box",
width: 57, // inches
length: 137, // inches
fillDepth: 5, // inches
};
let gardenList = [
beanBed,
tomatoBox,
];
gardenList.forEach(doCalculations);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment