代码STILL无法识别错误的输入 [英] Code STILL not recognizing incorrect input

查看:66
本文介绍了代码STILL无法识别错误的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然遇到此代码的问题。我使用if(inputValue == temp);而它仍然无法正常工作。还有其他想法吗?它对其他人有用吗?



我写了一个程序,提示用户输入数学问题。如果输入正确则显示正确,但如果输入不正确,则表示正确。找不到错误。有什么建议?谢谢!

 <   script     language   =  JavaScript >  <   / script  >  
< style type = text / css >
.style1 {
font-family:Arial;
font-size:x-small;
}
< / style >
< / head >

< body > < p > < script > <! - 隐藏旧版浏览器

var inputText,反馈; //用于保存用户输入和反馈的变量

var inputValue,loopCounter,correctCount,temp; //整数变量



loopCounter = 0; //设置变量的起始值

correctCount = 0;



var num1,num2;



num1 = Math.round(Math.random()* 100);

num2 = Math.round(Math.random()* 100);



inputText = window.prompt(什么是+ num1 +加+ num2 +?输入-1停止。,0);



inputValue = parseInt(inputText);



while(inputValue!= -1){

temp = num1 + num2;

if(inputValue == temp){

correctCount ++;

feedback =正确!;

}否则if(inputValue!= temp){

feedback =抱歉。不正确;

}

loopCounter ++;

num1 = Math.round(Math.random()* 100);

num2 = Math.round(Math.random()* 100);

inputText =;

inputText = window.prompt(+ feedback +现在,什么是+ num1 +加上+ num2 +?(输入-1停止:),0);

inputValue = 0;

inputValue = parseInt(inputText);

}



document.write(< font size ='5'color ='#0000FF'>< b>您已经在+ loopCounter +尝试中更正了+ correctCount +。< / b>< / font>)

解决方案

请检查下面的图像链接,如果没有看到图像中描述的对话框,请告诉我。

http://steppic.com/preview/73f44db94b64926fddc70a8839f21078.png

I am still having problems with this code. I used if(inputValue == temp); and it's still not working. Any other ideas? Does it work for anyone else?

I wrote a program that prompts user input for a math question. It says "Correct" if the input is correct, but it also says "correct" if the input is not correct. Can't find the error. Any suggestions? Thank you!

<script language="JavaScript"></script>
<style type="text/css">
.style1 {
    font-family: Arial;
    font-size: x-small;
}
</style>
</head>

<body><p><script><!-- hide from old browser

var inputText, feedback;   // variables for holding user input and feedback

var inputValue, loopCounter, correctCount, temp;  // integer variables



loopCounter = 0;  // set the starting value of variables

correctCount = 0;



var num1, num2;



num1 = Math.round(Math.random()*100);

num2 = Math.round(Math.random()*100);



inputText = window.prompt("What's " + num1 + " plus " + num2 + "? Enter -1 to stop.", "0");



inputValue = parseInt(inputText);



while (inputValue != -1){

          temp = num1 + num2;

          if (inputValue == temp){

            correctCount++;

            feedback = "Correct! ";

          } else if (inputValue != temp) {

            feedback = "Sorry. Not correct";

          }

          loopCounter++;

          num1 = Math.round(Math.random()*100);

          num2 = Math.round(Math.random()*100);

          inputText = "";

          inputText = window.prompt("" + feedback + "Now, what's " + num1 + " plus " + num2 + "? (Enter -1 to stop:)", "0");

          inputValue = 0;

          inputValue = parseInt(inputText);

}



document.write("<font size='5' color='#0000FF'><b>You have got " + correctCount + " correct out of " + loopCounter + " tries.</b></font>")

解决方案

Kindly check the image link below and let me know if you don't see a dialog box as described in the image.
http://steppic.com/preview/73f44db94b64926fddc70a8839f21078.png


这篇关于代码STILL无法识别错误的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆