我有这个算法来计算投票的平均值:(a + 2b + 3c + 4d + 5e + 6f + 7g + 8h + 9i + 10j)/(a + b + c + d + e + f + g + h + i + j)
但问题是我想为每个点击某人点击的变量添加一个,并在重新加载后显示平均值。
ex:. a = 25 //the amount of people who voted "1";
b = 19 //the amount of people who voted "2";
c = 78 //the amount of people who voted "3";
d = 98 //the amount of people who voted "4";
e = 69 //the amount of people who voted "5";
average = (a + 2b + 3c + 4d + 5e + 6f + 7g + 8h + 9i + 10j) / (a + b + c + d + e + f + g + h + i + j);
alert(average); // Alerts 3,5
有人点击“d”,另外十个人点击“e”
adds +1 to "d"
adds +1 to "e" (10x)
alerts the new average on reload.
这就是我想要它做的,但我不知道如何使用 cookie(如果有必要)