Food-chain problem in Javascript