Document objectWindow object
Window object has two properties, document and window,
which refer to the document and window objects, respectivelyDocument object has a method, write, which dynamically creates content
document.write("Answer: " + result + "<br />");Window object has three methods for creating dialog boxes, alert, confirm,
and promptalert("Hej! \n");
OK buttonconfirm("Do you want to continue?");
OK and Cancelprompt("What is your name?", "");
OK and CancelOK without typing a response in the text box (waits for OK)
<!DOCTYPE html>
<!-- roots.html
A document for roots.js
-->
<html lang = "en">
<head>
<title> roots.html </title>
<meta charset = "utf-8" />
</head>
<body>
<script type = "text/javascript" src = "roots.js" >
</script>
</body>
</html>
// roots.js
// Compute the real roots of a given quadratic
// equation. If the roots are imaginary, this script
// displays NaN, because that is what results from
// taking the square root of a negative number
// Get the coefficients of the equation from the user
var a = prompt("Find the solution for ax^2 + bx +c \n What is the value of 'a'? \n", "");
var b = prompt("What is the value of 'b'? \n", "");
var c = prompt("What is the value of 'c'? \n", "");
// Compute the square root and denominator of the result
var root_part = Math.sqrt(b * b - 4.0 * a * c);
var denom = 2.0 * a;
// Compute and display the two roots
var root1 = (-b + root_part) / denom;
var root2 = (-b - root_part) / denom;
document.write("The first root is: ", root1, "<br />");
document.write("The second root is: ", root2, "<br />");
Create a webpage with JavaScript to ask user entering width and length of a rectangle. Take the user's answers and display the area and perimeter of the rectangle.