失踪 ;在Google脚本

时间:2018-03-09 15:00:39

标签: javascript google-apps-script percentile

我在谷歌脚本中尝试我的第一步,我尝试连续计算给定数字范围的百分位数。我总是有一个

失踪;在声明之前。 (第107行,文件“Sitan_Code”)错误

我没有看到这一点,为什么我得到这个。

任何人都可以帮忙吗?

提前致谢

function percentile() {
  var tenPercent = 10 / 100; //simsSheet.getRange("I5").getValue() / 100;
  var twentyfivePercent = 25 / 100; //simsSheet.getRange("I6").getValue() / 100;
  var fiftyPercent = 50 / 100; //simsSheet.getRange("I7").getValue() / 100;
  var seventyfivePercent = 75 / 100; //simsSheet.getRange("I8").getValue()/ 100;
  var neintyPercent = 90 / 100; // simsSheet("I9").getValue() / 100;
  var values = simsSheet.getRange("A1:NTP1").getValues().sort();
  var percentage = [tenPercent, twentyfivePercent, fiftyPercent, seventyfivePercent, neintyPercent];

  for (i = 0; i < percentage.length; i++) {
    var index = values.length * percentage[i];

    if ((index % 2) === 0) {

      var average = (index[i] + index[i + 1]) / 2;

      if (percentage[i] == percentage[tenPercent]) {
        var ten = simsSheet.getRange("K5") set.Value(average);
      } else if (percentage[i] == percentage[twentyfivePercent]) {
        var twentyfive = simsSheet.getRange("K6").setValue(average);
      } else if (percentage[i] == percentage[fiftyPercent]) {
        var fivty = simsSheet.getRange("K7").setValue(average);
      } else if (percentage[i] == percentage[seventyfivePercent]) {
        var seventyfive = simsSheet.getRange("K8").setValue(average);
      } else if (percentage[i] == percentage[neintyPercent] {
          var neinty = simsSheet.getRange("K9").setValue(average);
          else {
            inx = Math.round(index);
          }

1 个答案:

答案 0 :(得分:0)

您的代码似乎缺少一些导致编译失败的大括号和句点,请参阅下面的版本:

function percentile() {
    var tenPercent = 10 / 100; //simsSheet.getRange("I5").getValue() / 100;
    var twentyfivePercent = 25 / 100; //simsSheet.getRange("I6").getValue() / 100;
    var fiftyPercent = 50 / 100; //simsSheet.getRange("I7").getValue() / 100;
    var seventyfivePercent = 75 / 100; //simsSheet.getRange("I8").getValue()/ 100;
    var neintyPercent = 90 / 100; // simsSheet("I9").getValue() / 100;
    var values = simsSheet.getRange("A1:NTP1").getValues().sort();
    var percentage = [tenPercent, twentyfivePercent, fiftyPercent, seventyfivePercent, neintyPercent];

    for (i = 0; i < percentage.length; i++) {
        var index = values.length * percentage[i];

        if ((index % 2) === 0) {

            var average = (index[i] + index[i + 1]) / 2;

            if (percentage[i] == percentage[tenPercent]) {
                var ten = simsSheet.getRange("K5").setValue(average);
            } else if (percentage[i] == percentage[twentyfivePercent]) {
                var twentyfive = simsSheet.getRange("K6").setValue(average);
            } else if (percentage[i] == percentage[fiftyPercent]) {
                var fivty = simsSheet.getRange("K7").setValue(average);
            } else if (percentage[i] == percentage[seventyfivePercent]) {
                var seventyfive = simsSheet.getRange("K8").setValue(average);
            } else if (percentage[i] == percentage[neintyPercent]) {
                var neinty = simsSheet.getRange("K9").setValue(average);
            } else {
                inx = Math.round(index);
            }
        }
    }
}