嗨,我試着做一些計算如下。變量在JavaScript本地函數中沒有得到值
重量值應該從分數中減去它的值。但是當我這樣做時,我得到了「undefined」作爲score
變量輸出。是什麼原因?我是否正確處理變量聲明?
var score = 10;
var scoresFunc = function (weight) {
console.log(score);
var finalScore = score - weight;
score = score - finalScore;
var scoreForStartingDate = $('#scoreForStartingDate').val();
var scoreForDuration = $('#scoreForDuration').val();
var scoreForProjects = $('#scoreForProjects').val();
var score = score - parseInt(weight);
var a = '';
for (i = 1; scores >= i; i++) {
a += "<option value='" + i + "'>" + i + "</option>";
}
return a;
};
你在哪裏得到未定義? –
完全提到錯誤,而不是說只是'undefined' –
請參閱控制檯日誌。分數變量給了undefined – GRTZ