Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.