javascript - 努力学习乘法
问题描述
问题是,当我输入正确答案时,文本不会变成绿色,而当它不正确时,它不会变成红色。我认为有一个问题是我没有得到输入值,但可以找到解决方法。
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;
<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>
解决方案
您对该函数的调用未传递任何参数
推荐阅读
- mybatis - mybatis foreach 但提交单独的插入
- python - docker 如何处理文件路径?
- java - 从 android studio 中的列表视图中获取选项名称
- python - 使用reportlab生成的pdf文件,保存为纯文本
- twilio - 每小时或每天获取 Twilio SMS 故障的最佳方法
- go - 了解内存分配的工作原理和垃圾收集器
- python - django admin InlineModel 中的图像
- android - Gradle 同步失败:找不到 com.android.tools.build:gradle:1.0.+ 的任何匹配项,因为没有可用的 com.android.tools.build:gradle 版本
- java - 第一批后关闭 Spark Streaming Context(尝试检索 kafka 偏移量)
- gradle - Protobuf Gradle 插件版本 0.8.6 及更高版本与 Project 'flutter_blue' 使用版本 0.8.3