本文介绍了请查看错误,每件事都写正确甚至出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,如果我们没有正确输入坐标,则应该支付"improper coordinates entered"

My problem is if we do not enter coordinates properly it should dispay "improper coordinates entered"

<html>
<head>
  <title>CALUCLATING AREA AND PERIMETER</title>
<center><h1>CALUCLATOR FOR AREA & PERIMETER</h1></center>

  <style>

  </style>

  <script language="JavaScript">

    var x = new Array();
    var y = new Array();
    var vertices;
    var digits;
    var area;
    var perimeter;
    var r;
    var carea;
    var cperi;
    var m;

    function readUserData()
    {

        vertices = parseInt( document.getElementById("VERTICES").value );
        if( (vertices < 2) || (vertices > 10 ) ) {
            alert( "Vertices must be >= 2 and <= 10" );
            return;
        }





        for( k = 0; k < vertices; k++ ) {
           if((x[k]==="undefined")&&(y[k]==="undefined"))
           {
             m=k+1;
           alert("improper coordinates entered at vertex position: "+m);
            exit(1);
           }
            x[k] = parseInt( document.getElementById("X"+k).value );
            y[k] = parseInt( document.getElementById("Y"+k).value );
        }

        x[vertices] = x[0];
        y[vertices] = y[0];
    }

    function calculateArea()
    {

        area = 0.0;

        for( k = 0; k < vertices; k++ ) {
            xDiff = x[k+1] - x[k];
            yDiff = y[k+1] - y[k];
            area = area + x[k] * yDiff - y[k] * xDiff;
        }
        area = 0.5 * Math.abs(area);
    }

    function calculatePerimeter()
    {


        perimeter = 0.0
        for( k = 0; k < vertices-1; k++ ) {
            xDiff = x[k+1] - x[k];
            yDiff = y[k+1] - y[k];
            perimeter = perimeter +
                        Math.pow( xDiff*xDiff +
                        yDiff*yDiff, 0.5 );
        }
    }
function cir()
 {
 r= parseInt(document.getElementById("Y"+10).value);
 carea=3.1429*(r*r);
 cperi=6.2858*r;
alert(" circle area is "+carea);
alert(" circle perimeter is"+cperi);
}



    function handleCalculate()
    {
        readUserData();
        calculateArea();
        calculatePerimeter();

        alert("area is  "+area);
        alert("PERIMETER IS  "+perimeter);

    }


  </script>
</head>

<body>
<div align="center">
<div class="content">
<form>
<table border="2" cellspacing="0">
         cellpadding="2" style="border-collapse: collapse">

<tr>
<td colspan="2">Number of Vertices
<input type="text" id="VERTICES" 

          size="5" value="0"></td>

</tr>
<tr>
<td align="center">Vertex</td>
<td colspan="2" align="left">X Value</td>
<td align="left">Y Value</td>
</tr>
<tr>
<td align="center">1</td>
<td colspan="2"><input type="text" 

               id="X0" size="20"></td>
<td><input type="text" id="Y0" size="20"></td>
</tr>
<tr>
<td align="center">2</td>
<td colspan="2"><input type="text" 

             id="X1" size="20"></td>
<td><input type="text" id="Y1" size="20"></td>
</tr>
<tr>
<td align="center">3</td>
<td colspan="2"><input type="text" 

             id="X2" size="20"></td>
<td><input type="text" id="Y2" size="20"></td>
</tr>
<tr>
<td align="center">4</td>
<td colspan="2"><input type="text" 

            id="X3" size="20"></td>
<td><input type="text" id="Y3" size="20"></td>
</tr>
<tr>
<td align="center">5</td>
<td colspan="2"><input type="text" 

           id="X4" size="20"></td>
<td><input type="text" id="Y4" size="20"></td>
</tr>
<tr>
<td align="center">6</td>
<td colspan="2"><input type="text" 

          id="X5" size="20"></td>
<td><input type="text" id="Y5" size="20"></td>
</tr>
<tr>
<td align="center">7</td>
<td colspan="2"><input type="text" 

         id="X6" size="20"></td>
<td><input type="text" id="Y6" size="20"></td>
</tr>
<tr>
<td align="center">8</td>
<td colspan="2"><input type="text" 

         id="X7" size="20"></td>
<td><input type="text" id="Y7" size="20"></td>
</tr>
<tr>
<td align="center">9</td>
<td colspan="2"><input type="text" 

         id="X8" size="20"></td>
<td><input type="text" id="Y8" size="20"></td>
</tr>
<tr>
<td align="center">10</td>
<td colspan="2"><input type="text" 

         id="X9" size="20"></td>
<td><input type="text" id="Y9" size="20"></td>
</tr>

<tr>
<td align="center"><input type="button" 

    value="Calculate"  önClick="handleCalculate()"></td>

<td align="center">
<input type="reset" value="Reset"></td>
</tr>
<tr><td>for circle:</td></tr>
<tr><td>ENTER radius <input type="text" id="Y10" size="20"></td></tr>
<tr><td><input type="button" value="circleCaluclator"  önClick="cir()"></td></tr>

</form>
</table></div>
</div>
</body>
</html>

推荐答案


这篇关于请查看错误,每件事都写正确甚至出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:40