所以generateOTP()应该给我一个随机数,它将显示在文本“ Enter the Number Above”上方,它可以工作,但是在我添加第二个函数后,它消失了。该程序应该做的是显示一个随机数,然后在该数字与该随机数匹配时输入下一个数字,这将给出一条消息“您的答案与上述数字匹配”,否则您的答案与上述数字不匹配。”请帮助
<html>
<head>
<title>Simulating One-Time-Password (OTP) or CAPTCHA</title>
<meta charset="UTF-8">
<meta name="description" content="Simulating One-Time-Password (OTP) or CAPTCHA">
<meta name="keywords" content="java, otp">
<meta name="author" content="sad">
<style>
</style>
<script>
function generateOTP() {
// Declare a digits variable
// which stores all digits
var digits = '0123456789';
let OTP = '';
for (let i = 0; i < 6; i++ ) {
OTP += digits[Math.floor(Math.random() * 10)];
}
return OTP;
}
document.write("OTP of 6 digits: ")
document.write( generateOTP() );
var ranNum = generateOTP();
function checkValue(){
var finalAnswer =
document.getElementById("answer").value;
if (ranNum== finalAnswer) {
document.write("Your answer matches the number above")
else{
document.write("Your answer does not match the number above")
}
}
}
</script>
</head>
<body>
<p> Enter the number above
<input id="answer" type="text"/>
</p>
<p>
<button onclick="checkValue()"> Display </button>
</p>
</body>
</html>
答案 0 :(得分:2)
您在class MainActivity extends Activity{
...
@Override
public void onSongSelected(String title, String content){
bottomSheet.titleView.setText(title);
bottomSheet.contentView.setText(content);
}
}
语句中输入了else
关键字。应该是:
if