First iteration of javascript function