Remaining days in the last week
let RemDays = N % 7 ; let X = 28 * CompWeeks + 7 * Math . floor ( ( CompWeeks * ( CompWeeks - 1 ) / 2 ) ) ; let Y = RemDays * Math . floor ( ( RemDays + 1 ) / 2 ) + CompWeeks * RemDays ; let cost = X + Y ; document . write ( cost , ' ' ) ; }