我正在尝试开发一款可以帮助我锻炼身体并不断提高力量的应用程序,以便变得更强壮。当我尝试将变量输出到HTML时,在最底部始终出现错误“无法设置null的内部属性”。这是注释的最后一部分下的代码,我遇到了错误。可以给我一些如何解决此问题的指导吗?
//Get the variables from the user. This will be the previous exercise or the exercise that the user has performed
const userSet = document.getElementById("set-user-1");
const userReps = document.getElementById("reps-user-1");
const userWeight = document.getElementById("weight-user-1");
var futureSet;
var futureReps;
var futureWeight;
//Define the functions that need to be done between the previous exercise and the next exercise
function getNewSet(previousSet) {
return previousSet;
}
function getNewRep(previousReps){
if(previousReps < 12) {
return previousReps + 2;
} else {
previousReps = 6;
return previousReps;
}
}
function getNewWeight(previousReps, previousWeight) {
if(previousReps < 12){
return previousWeight;
} else {
previousWeight = previousWeight + 10;
return previousWeight;
}
}
//Make a function that runs all the functions with the user input
function getNewWorkout() {
futureSet = getNewSet(parseInt(userSet));
futureReps = getNewRep(parseInt(userReps));
futureWeight = getNewWeight(parseInt(userReps, userWeight));
return futureSet;
return futureReps;
return futureWeight;
}
//Output will go to the future exercise dividers
document.getElementById("future-sets").innerHTML = futureSet;
document.getElementById("future-reps").innerHTML = futureReps;
document.getElementById("future-weight").innerHTML = futureWeight;
当您在DOM准备就绪之前加载脚本时会出现这种错误。您可以尝试在HTML末尾加载脚本,通常在页脚中。这应该可以解决您的错误。
错误出现在此函数的后两行。一个函数只能返回一个值,可能值得将所有值放入数组中然后返回它。