working on a rate function using JS