figuring out the math portion of this JavaScript