【发布时间】:2016-04-11 15:18:05
【问题描述】:
我有一个小提琴here。
我正在尝试
-
根据 2-6 个回答计算平均评分(答案可以是:
0, 1, 2或NA,并被称为"1a", "1b", "1c", "2a"等)。我有一个 正确平均收视率的脚本,但产生"0"每当所有答案都是"NA"。我还需要产生的平均值 只要所有答案都是"NA",就成为"NA"。这是我的代码:
var aField = new Array("1a", "1b", "1c") //create an array of the fields you need to check the value of var aScore = new Array(); //creating an empty array for further use var nScore = 0; //creating a variable holding the sum of the scores for (var i = 0; i < aField.length; i++){ //looping through every item of array aField if (this.getField(aField[i]).value >= 0){ //if our value is a number eliminating 0, nothing and NA aScore.push(aField[i]); //we will count the number of correct values with this array; nScore += Number(this.getField(aField[i]).value); // we add the value to our total } } if (aScore.length >0){ //We don't want to divide our score by 0 because it's impossible event.value = nScore/aScore.length; //we devide the result by the number of correct values in the array.有人建议使用以下代码来解决问题,但是当 我运行它,我收到了一个
"语法错误:缺失;在语句 12 之前: 在第 13 行"
消息。 (不知道问题是什么,但如果有人 可以找到它/修复代码,非常感谢)。
var allFieldsAreNA = true; for (var i = 0; i < aField.length; i++){ if ( this.getField(aField[i]).value >= 0 ) { allFieldsAreNA = false; break; } } If( allFieldsAreNA == false ) { // do the code you already have } else { event.value = “NA”; // or something like that } 我需要得到一个脚本,它采用平均评分并将其乘以各种
"Weight Factors"(例如,0.15, 0.1等)。如果平均。评级是一个数字,然后它只是乘以,如果平均。评级是"NA",那么"Weighted Rating"也是"NA"。将所有
"Weighted Ratings"相加并除以"Weight Factors"的总和的脚本。如果所有字段都计算为数字,则总权重因子为1.0或100%(.1, .15, .15, .1, .15, .25, .1),总"Weighted Ratings"除以1.0等于... 987654343@,则应相应计算总"Weight Factors"(类别6 is NA的加权评级,因此Weight Factors应仅为.1 + .15 +.15 + .1 + .15 + .1),总"Weighted Ratings" / 0.75。
任何帮助,不胜感激。
【问题讨论】:
标签: javascript adobe acrobat