我正在编写一个不提供输出的代码 [英] i am write an code which is not give the output

查看:54
本文介绍了我正在编写一个不提供输出的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!DOCTYPE html>
<html>
<body>

<p>Click the button </p>

<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
   var i=0;
   var j=0;
   var svalue = new Array(5);
   var namx=0;
   while(i<5){
      var person = parseInt(prompt("Please enter your number"));
      i++;
      svalue[person];
   } 
   for(j=0;j<svalue.length;j++)>
   {
      if(svalue[j]>nmax)
      {
         nmax=svalue[j];
      }
   }
   document.write(nmax);
}
</script>
</body>
</html>

推荐答案

开始通过改变

Start by changing
svalue[person];



To

svalue[i++] = person;

并删除它上面的行。

然后在它的声明中更正nmax的名称...

And remove the line above it.
Then correct the name of nmax in it's declaration...


那里是代码中的错误。尝试

There are erros in your code. Try
<!DOCTYPE html>
<html>
<body>

<p>Click the button </p>

<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction(){
   var i=0;
   var j=0;
   var svalue = new Array(5);
   var nmax=0;
   while(i<5){
      var person = parseInt(prompt("Please enter your number"));
      svalue[i] = person;
      i++;

   }
   for(j=0;j<svalue.length;j++)
   {
      if(svalue[j]>nmax)
      {
         nmax=svalue[j];
      }
   }
   document.write(nmax);
}

</script>
</body>
</html>






请使用以下代码。

用下面的替换你的javascript函数

Please use below code.
Replace your javascript function with below one
function myFunction() {
           var i = 0;
           var j = 0;
           var svalue = [];
           var nmax = 0;
           for (i = 0; i < 5; i++) {
               var person = parseInt(prompt("Please enter your number"));
               svalue[i] = person;
           }
           for (j = 0; j < svalue.length; j++) {
               if (svalue[j] > nmax) {
                   nmax = svalue[j];
               }
           }
           document.write(nmax);
       }



它会写出你输入的最大值。


It will write the maximum value you entered.


这篇关于我正在编写一个不提供输出的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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