Javascript True/false作为字符串,仅允许boolen 函数开始(){ var arrNums=[18,23,20,17,21,18,22,19,18,20]; var低值、高值、指数、计数; lowValue=Number(document.getElementById(“lowValue”).value); highValue=Number(document.getElementById(“highValue”).value); 指数=0; 计数=0; document.getElementById(“msg”).innerHTML+=“数组中的值为:”; while(索引
而不是使用Javascript True/false作为字符串,仅允许boolen 函数开始(){ var arrNums=[18,23,20,17,21,18,22,19,18,20]; var低值、高值、指数、计数; lowValue=Number(document.getElementById(“lowValue”).value); highValue=Number(document.getElementById(“highValue”).value); 指数=0; 计数=0; document.getElementById(“msg”).innerHTML+=“数组中的值为:”; while(索引,javascript,Javascript,而不是使用return(“true”)和return(“false”),则使用return true和return false 另外,将if(validateLowWandHigh(lowValue,highValue)=“true”)替换为 if(validateLowAndHigh(lowValue,highValue)) 或 如果(validateLowWandHigh(lowValue,highValue)==true)而不是使用返回(“true”)和返回(“false”),则使用返回t
return(“true”)
和return(“false”)
,则使用return true
和return false
另外,将if(validateLowWandHigh(lowValue,highValue)=“true”)
替换为
if(validateLowAndHigh(lowValue,highValue))
或
如果(validateLowWandHigh(lowValue,highValue)==true)
而不是使用返回(“true”)
和返回(“false”)
,则使用返回true
和返回false
另外,将if(validateLowWandHigh(lowValue,highValue)=“true”)
替换为
if(validateLowAndHigh(lowValue,highValue))
或
if(validateLowAndHigh(lowValue,highValue)==true)
如下更改代码
返回true
而不是返回(“true”)或(“false”)
if(validateLowAndHigh(lowValue,highValue))
改为if(validateLowAndHigh(lowValue,highValue)='true')
函数开始(){
var arrNums=[18,23,20,17,21,18,22,19,18,20];
var低值、高值、指数、计数;
lowValue=Number(document.getElementById(“lowValue”).value);
highValue=Number(document.getElementById(“highValue”).value);
指数=0;
计数=0;
document.getElementById(“msg”).innerHTML+=“数组中的值为:”;
while(索引 如果(arrNums[index]>=lowValue&&arrNums[index]像这样更改代码
更改返回true
而不是返回(“true”)或(“false”)
并将if(validateLowAndHigh(lowValue,highValue))
改为if(validateLowAndHigh(lowValue,highValue)='true')
函数开始(){
var arrNums=[18,23,20,17,21,18,22,19,18,20];
var低值、高值、指数、计数;
lowValue=Number(document.getElementById(“lowValue”).value);
highValue=Number(document.getElementById(“highValue”).value);
指数=0;
计数=0;
document.getElementById(“msg”).innerHTML+=“数组中的值为:”;
while(索引 如果(arrNums[index]>=lowValue&&arrNums[index],为什么需要它们作为字符串?字符串始终为true。只需使用false和true而不带“…”。为什么需要它们作为字符串?字符串始终为true。只需使用false和true而不带“…”。
function start() {
var arrNums = [18,23,20,17,21,18,22,19,18,20];
var lowValue, highValue, index, count;
lowValue = Number(document.getElementById("lowValue").value);
highValue = Number(document.getElementById("highValue").value);
index = 0;
count = 0;
document.getElementById("msg").innerHTML+="The values in the array are: ";
while(index < arrNums.length) {
document.getElementById("msg").innerHTML+= arrNums[index] + " ";
index++;
}
index = 0;
if(validateLowAndHigh(lowValue, highValue) == "true") {
while(index < arrNums.length) {
if(arrNums[index] >= lowValue && arrNums[index] <= highValue) {
count++;
}
index++;
}
document.getElementById("msg").innerHTML+= "<br/> There are " + count + " values that exist in this range";
}
}
function validateLowAndHigh(low, high) {
if(low <= high) {
return("true");
} else {
document.getElementById("msg").innerHTML+= "<br/> Low value must be less than or equal to the high vaules";
return("false");
}
}
function clearOutput() {
document.getElementById("msg").innerHTML=" ";
}
function start() {
var arrNums = [18, 23, 20, 17, 21, 18, 22, 19, 18, 20];
var lowValue, highValue, index, count;
lowValue = Number(document.getElementById("lowValue").value);
highValue = Number(document.getElementById("highValue").value);
index = 0;
count = 0;
document.getElementById("msg").innerHTML += "The values in the array are: ";
while (index < arrNums.length) {
document.getElementById("msg").innerHTML += arrNums[index] + " ";
index++;
}
index = 0;
if (validateLowAndHigh(lowValue, highValue)) {
while (index < arrNums.length) {
if (arrNums[index] >= lowValue && arrNums[index] <= highValue) {
count++;
}
index++;
}
document.getElementById("msg").innerHTML += "<br/> There are " + count + " values that exist in this range";
}
}
function validateLowAndHigh(low, high) {
if (low <= high) {
return true;
} else {
document.getElementById("msg").innerHTML += "<br/> Low value must be less than or equal to the high vaules";
return false;
}
}
function clearOutput() {
document.getElementById("msg").innerHTML = " ";
}