Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here\'s what I have to do: I have to create an HTML page using Javascript that p

ID: 3547320 • Letter: H

Question

Here's what I have to do:  I have to create an HTML page using Javascript that prompts the user to enter two positive numbers.  

(NOTE: If the user enters a negative number, the input area should come up again, stating that the user should enter only a positive number).

Under the button, once the numbers are entered, one at a time, the solutions to the three problems will appear, based on the numbers entered.  


the first should calculate the first number (X) to the power of the second number (Y)

the second should calculate the area of a right triangle (based on a=1/2base * height)

the third should calculate the distance between two points (the first is the number entered (x,y), the second is (0,0))


Here's what I have so far, including my equations.  



<script type="text/javascript">

function bigMath()

{

var x=prompt"Enter First Number - must be positive";

if x<0

{ "This number is negative.  Please enter a positive number"

}

var y=prompt"Enter second number - must be positive";

if y<0

{ "This number is negative. Please enter a positive number"

}

  

   function firstExp()

   {

   var exp=pow(x,y);

   }

  

   function secondArea()

   {

   var area=((0.5*x)*y);

   }

  

   function thirdDistance()

   {

var pointTwoLat = 0;

   var pointTwoLong = 0;

   var diffOne;

   var diffTwo;

diffOne=(pointTwoLat - x);

diffOne=(diffOne * diffOne);

   diffTwo=(pointTwoLong - y);

   diffTwo=(diffTwo * diffTwo);

   return Math.sqrt( diffTwo + diffOne );

   }

  

  

}


</script>


<body>

<form name="form1">


<p><input type="Button" value="Enter Two numbers" /></p>


<p id="newText"

</body>


</html>

Explanation / Answer


<script type="text/javascript">


function bigMath()

{


var x=0;

var y=0;


x=prompt("Enter First Number - must be positive");

if (x < 0)

{

alert("This number is negative. Please enter a positive number");

x=prompt("Enter First Number - must be positive");

}


y=prompt("Enter second number - must be positive");

if (y<0)

{

alert("This number is negative. Please enter a positive number");

y=prompt("Enter second number - must be positive");

}


function firstExp(a,b)

{

return ( Math.pow(a,b) );

}


function secondArea(a,b)

{

return (0.5*a*b);

}


function thirdDistance(a,b)

{

var pointTwoLat = 0;

var pointTwoLong = 0;

var diffOne;

var diffTwo;

diffOne=(pointTwoLat - x);

diffOne=(diffOne * diffOne);

diffTwo=(pointTwoLong - y);

diffTwo=(diffTwo * diffTwo);

return Math.sqrt( diffTwo + diffOne );

}


document.getElementById("lbl1").innerHTML = "Power is :- " + firstExp(x,y) ;

document.getElementById("lbl2").innerHTML = "Area is :- " + secondArea(x,y) ;

document.getElementById("lbl3").innerHTML = "Distance is :- " + thirdDistance(x,y) ;

}


</script>


<body>

<h3 align ="center">

<input type="Button" value="Enter Two numbers" />

<p id="lbl1" > Answer -1 </p>

<p id="lbl2" > Answer -2 </p>

<p id="lbl3" > Answer -3 </p>

</h3>

</body>


</html>