added loops in JS