问题是当我输入正确的答案时,文本不会变为绿色,而当输入不正确时,文本不会变为红色。我认为有一个问题,我没有输入值,但可以找到解决方法。
var parentFolder = DriveApp.getFolderById(folderId);
var studyFolder = parentFolder.createFolder(folderName);
var studyFolderUrl = studyFolder.getUrl();
var firstArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var secondArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var first = firstArray[Math.floor(Math.random() * firstArray.length)];
var second = secondArray[Math.floor(Math.random() * secondArray.length)];
var sum = firstArray[first - 1] * secondArray[second - 1];
function fn1(sum, n1) {
var n1 = document.getElementById("n1").value;
if (sum < n1) {
document.getElementById("pp").style.background = "green";
} else if (sum > n1) {
document.getElementById("p").style.background = "red";
} else {
document.getElementById("p").style.background = "blue";
document.getElementById("pp").style.background = "blue";
}
};
document.getElementById("p").innerHTML = first;
document.getElementById("pp").innerHTML = second;
document.getElementById("a").innerHTML = first;
document.getElementById("b").innerHTML = second;
document.getElementById("sum").innerHTML = sum;
答案 0 :(得分:1)
您对该函数的调用未传递任何参数
答案 1 :(得分:0)
您的函数fn1()无需争论
var firstArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var secondArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var first= firstArray[Math.floor(Math.random() * firstArray.length)];
var second= secondArray[Math.floor(Math.random() * secondArray.length)];
var sum = firstArray[first- 1] * secondArray[second - 1];
function fn1() {
var n1 = document.getElementById("n1").value;
if (sum < n1) {
document.getElementById("pp").style.background = "green";
} else if (sum > n1) {
document.getElementById("p").style.background = "red";
} else {
document.getElementById("p").style.background = "blue";
document.getElementById("pp").style.background = "blue";
}
};
document.getElementById("p").innerHTML = first;
document.getElementById("pp").innerHTML = second;
document.getElementById("a").innerHTML = first;
document.getElementById("b").innerHTML = second;
document.getElementById("sum").innerHTML = sum;
<h1>Learn to Multiply</h1>
<h1> <a id="a"></a> * <a id="b"></a> = <input type="text" id="n1" name="txt"></h1>
<button onclick="fn1()" id="btn1">Clcik me</button>
<p id="p"></p>
<p id="pp"></p>
<p id="sum"></p>
<p id="test"></p>
答案 2 :(得分:0)
更改为此:
// first remove the parameters
function fn1() {
var n1 = document.getElementById("n1").value;
// I think you want green when is equal
if (sum == n1) {
document.getElementById("pp").style.background = "green";
} else if (sum > n1) {
document.getElementById("p").style.background = "red";
} else {
document.getElementById("p").style.background = "blue";
document.getElementById("pp").style.background = "blue";
}
};