Last active
July 8, 2019 21:59
-
-
Save jasonmccallister/33e9a73e02d3bbf4ed406e78c80a1065 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var candies = []; | |
var boxes = []; | |
// var boxes = [{"number": 1, "count": 12, "weight": 8.093},{"number": 2, "count": 16, "weight": 9.3}]; | |
function makeCandies(num) { | |
var i = 0; | |
for (i = 0; i < num; i++) { | |
candies.push({ | |
name: "candy", | |
weight: getWeight() | |
}); | |
} | |
return candies; | |
} | |
function boxItUp() { | |
var boxNum = 1; | |
var box = {}; | |
var currentWeight = null; | |
var currentCount = 0; | |
while (candies.length) { | |
// make one long condition to keep it simple (two if checks in one line instead of nested if statements) | |
// if currentWeight is over 8oz and the currentCount is greater than 12 and an even number | |
// save the box to the boxes array | |
// boxNum++ to go to the next box count | |
// "zeroize" the box | |
// "zeroize" the currentWeight | |
// "zeroize" the currentCount | |
// else keep adding to the box object | |
// box.number = boxNum | |
// box.count = box.count++ | |
} | |
} | |
function getWeight() { | |
return (Math.random() * (0.55 - 0.75) + 0.75).toFixed(4); | |
} | |
makeCandies(10); | |
// boxItUp(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment