私はフィドルhereを持っています。N/Aをオプションとして計算する
私は2-6回答(回答ができ: 0, 1, 2
またはNA
、および"1a", "1b", "1c", "2a"
と呼ばれている、など)に基づいて平均格付けを計算
-
にしようとしています。私は スクリプトを使用して評価を正確に平均していますが、すべての回答が
私は平均格付けを取り、様々な
"Weight Factors"
(例えば、0.15, 0.1
、など)を掛けたスクリプトを取得する必要があります。 avg。 ratingは数値ですが、avgの場合は単純に乗算されます。評価が"NA"
の場合、"Weighted Rating"
も"NA"
です。"Weighted Ratings"
を合計し、合計を"Weight Factors"
で割るスクリプト。すべてのフィールドが数値であると計算される場合、総重み係数は1.0
または100%
(.1, .15, .15, .1, .15, .25, .1
)であり、1.0
で割った総"Weighted Ratings"
に等しい...NA
ある加重評価がある場合、総"Weight Factors"
は加重(それに応じて計算されるべきですカテゴリ6 is NA
の評価、したがってWeight Factors
は.1 + .15 +.15 + .1 + .15 + .1
である必要があります)、合計"Weighted Ratings"/0.75
です。
"NA"
であればいつでも
"0"
を生成します。すべての回答が
"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.
誰かが問題を解決するために、次のコードを示唆したが、 が、私はそれを実行したときに、私は
「にSyntaxError受け取っ:行方不明を、ステートメントの前に、 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
}
ご協力いただきありがとうございます。