Eloquent two arg function
by Rich Costello
JavaScript
/* basic version */
function printFarmInventory(cows, chickens) {
var cowString = String(cows);
while (cowString.length < 5)
cowString = "0" + cowString;
console.log(cowString + " Cows");
var chickenString = String(chickens);
while (chickenString.length < 5)
chickenString = "0" + chickenString;
console.log(chickenString + " Chicken");''
}
printFarmInventory(7, 11);
/*expanded version */
function zeroPad(number, width) {
var string = String(number);
while (string.length < width)
string = "0" + string;
return string;
}
function printFarmInventory(cows, chickens, pigs) {
console.log(zeroPad(cows, 3) + " Cows");
console.log(zeroPad(chickens, 3) + " Chickens");
console.log(zeroPad(pigs, 3) + " Pigs");
}
printFarmInventory(7, 16, 3);