var i = 1; var sum = 0; while(i <= 100) { // 判断分母是偶数还是奇数 偶数为- 正数为+ if(i % 2 == 0) { sum += -1/i; } else { sum += 1/i; } i++; } alert(sum)