2

我想在每次循环迭代后得到我的输出,但是当循环终止时它会给我输出。我无法理解为什么作为 JS 的新手面临这个问题。在我按 N 终止循环 n 提示关闭后,我在 webscreen 上得到输出。也许我看起来很愚蠢,但我无法解决它自己的问题,因为我正在收到问题禁令。

 <script type="text/javascript">
    do{
    var value1=prompt("enter 1st number::"," ");
    var value2=prompt("enter 2nd number::"," ");
    var op=prompt("Enter operator from(+,-,*,/,%age,average):");
    if (op=="+")
    {
        var result=parseInt(value1)+parseInt(value2);
        document.write("addition result is ="+result );
        document.write("<br/>");
    }
    else if(op=="-")
        
    {
        var result=parseInt(value1)-parseInt(value2);
        document.write("substraction result is ="+result );
    document.write("<br/>");
    }
    else if (op=="*")
    
        
    {
        var result=parseInt(value1)*parseInt(value2);
        document.write("multiplication  result is ="+result);
    document.write("<br/>");
    }
    else if (op=="/")
    
       
    {
        var result=parseInt(value1)/parseInt(value2);
        document.write("division  result is ="+result );
        document.write("<br/>");
    }
    else if (op=="%age")
    
       
    {
        var result=(parseInt(value1)/parseInt(value2))*100;
        document.write("percentage of value1 with value 2  is ="+result );
        document.write("<br/>");
    }
    else if (op=="average")
    
       
    {
        var result=(parseInt(value1)+parseInt(value2))/2;
        document.write("average   is ="+result );
        document.write("<br/>");
    }
    else
    {
       displa("Invalid input :" );
        document.write("<br/>"); 
    }
    var choice=prompt("Do you want to continue (Y/N)::"," ");
    }
    while(choice=="Y"||choice=="y");
    </script>
4

1 回答 1

1

你的代码ParseInt应该有语法错误parseInt,另外,建议使用Number对象的静态方法:Number.parseInt因为它通常更安全。

于 2020-10-23T15:42:29.010 回答