completed js version