我在构建函数时遇到问题。它应该检测用户放入框中的内容是否为整数,并打印正确的评论。问题出现在函数的第二级中,指令“if”应该再次检查图1是否是一个数字(它不会打印任何东西),但是“else if”被完美地读取,“else”也是如此。我的功能有什么问题?请帮忙。
function show() {
//Variable contains the value of field1 from input html which has been read thanks to onclick
var figure1 = document.getElementById("field1").value;
//Variable contains the value of field2 from input html which has been read thanks to onclick
var figure2 = document.getElementById("field2").value;
//empty until the instruction write in something
let sign = "";
//STEP 1
//loop working until the value of i reach the value of figure2
for (i = figure1; i <= figure2; i++)
{
if (Number(figure1) && Number(figure2)) {
//if both figure1 and figure2 are numbers, print the sign as follows - what sign contains from previous iteration + i + ", "
sign = sign + i + ", ";
} else {
if (Number(figure1)) {
//If statements from "if" level above haven't been fulfilled, print "Please, type integer in right-hand box";
sign = "Proszę wpisać liczbę w prawym polu";
} else if (Number(figure2)) {
//If statements from "if" level above haven't been fulfilled, print "Please, type integer in left-hand box";
sign = "Proszę wpisać liczbę w lewym polu";
} else {
sign = "Proszę wpisać wartości liczbowe w obu polach";
// If statements from "if"
// level above haven 't been fulfilled, print "Please, type integer in both boxes";
}
}
}
//podmienia wartość diva o id result na wartość zmiennej sign.
document.getElementById("result").innerHTML = sign;
}
犯罪嫌疑人X
MMTTMM
相关分类