Page 389 - Web_Application_v2.0_C12_Fb
P. 389
let imaginaryPart = (Math.sqrt(-determinant) / (2 * a)).toFixed(2);
document.getElementById("result").innerHTML = "The roots are complex: " +
realPart + " + " + imaginaryPart + "i and " + realPart + " - " + imaginaryPart
+ "i";
}};
</SCRIPT>
</BODY>
</HTML>
Output of the preceding code is as follows:
20. Create a webpage that accepts the radius of a circle and the user's choice. Using if-else statements and
the Math.pow() function in JavaScript, calculate and display the area or circumference of the circle based
on the user's selection, using Math.PI for the value of pi.
Ans. <!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>Circle Calculator</TITLE>
</HEAD>
<BODY>
<H1>Circle Calculator</H1>
<SCRIPT>
function calculate() {
var radius = parseFloat(document.getElementById("radius").value);
var choice = document.getElementById("calculation").value;
var answer = document.getElementById("result");
Practical Work 387

