javascript for grand game calculations