简体   繁体   English

如何制作一个带文本框的输入输出系统Html

[英]How to make an input and output system with a text box Html

I'm trying to make a bot that does equations that a standard calculator can't.我正在尝试制作一个可以执行标准计算器无法执行的方程式的机器人。 I'm okay with using HTML, CSS, and Javascript.我可以使用 HTML、CSS 和 Javascript。 I want it to do this: If I put a specific question in the textbox, like "Is 48 a composite or prime number?"我希望它这样做:如果我在文本框中输入一个特定的问题,例如“48 是合数还是质数?” it sends an alert and in the alert, it says "Composite" but I want it so I can put in multiple questions in the textbox, for now, I can only have one question or it crashes.它会发送一个警报,并在警报中显示“复合”,但我想要它,这样我就可以在文本框中输入多个问题,现在,我只能有一个问题,否则它会崩溃。 Here is my code so far.到目前为止,这是我的代码。

<!DOCTYPE html>
<html>
<input type="text" id="text" placeholder="text here"></input>
<button type="button" id="u" onclick="run()">submit</button>
<script type="text/javascript">

var a = 1;
function run() {
if (document.getElementById("text").value.includes("Is 48 a prime number or a composite number?")) {
alert("Composite");






  
document.body.innerHTML += "<li>attempt #" + a + ": correct";
a++
}
  
else {
alert("try again!")
document.body.innerHTML += "<li>attempt #" + a + ": try again";
a++
}


}

This is the code that makes the variable for the question.这是为问题创建变量的代码。

var a = 1;
function run() {
if (document.getElementById("text").value.includes("Is 48 a prime number or a composite number?")) {
alert("Composite");

I tried to copy and paste the code a few times it didn't work.我尝试复制并粘贴代码几次,但都没有用。 I tried to change the variable name the thing crashed.我试图更改崩溃的变量名称。

Thank you to anyone who helps.感谢任何提供帮助的人。

<!DOCTYPE html>
<html>
<input type="text" id="text" placeholder="text here"></input>
<button type="button" id="u" onclick="run()">submit</button>
<script type="text/javascript">

var a = 1;
function run() {
if (document.getElementById("text").value.includes("Is 48 a prime number or a composite number?")) {
alert("Composite");
}}






  
document.body.innerHTML += "<li>attempt #" + a + ": correct";
a++
}
  
else {
alert("try again!")
document.body.innerHTML += "<li>attempt #" + a + ": try again";
a++
}


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM