Input/Output Script Example

This is a simple input/output script where the user is prompted to enter the side of an equilateral triangle (all three sides equal). The script calculates the area of the triangle and outputs that to the user.

This is a load-time script, meaning the script executes as the browser is loading the page. To execute the script again, simply reload the page.

The built in document.write() function that writes the script output to the page only works during load-time. Once the page is fully loaded, document.write() can't add content to it.

JavaScript has many built-in functions such as document.write() and prompt() that are introduced in this example. Think of a built-in function as utility included in JavaScript to perform useful tasks for the scripter.