Output – JavaScript basics
You can use JS to display the output in different ways. Use window.alert() This function is used to display message alerts.
<!DOCTYPE html>
<html>
<body>
<h1>Code Projects</h1>
<p>Projects, Tutorials and More </p>
<script>
window.alert("ALERT");
</script>
</body>
</html>
Output:
Use innerHTML
The document.getElementById(id) method can be used in JS to access HTML elements. The Html element is defined by the id attribute, and the HTML content is defined by innerHTML.
<!DOCTYPE html>
<html>
<body>
<h1>Code Projects</h1>
<p>Projects, Tutorials and More </p>
<p id="ex"></p>
<script>
document.getElementById("ex").innerHTML = 50 + 50;
</script>
</body>
</html>
Output:
Use document.write( )
<!DOCTYPE html>
<html>
<body>
<h1>Code Projects</h1>
<p>Projects, Tutorials and More </p>
<script>
document.write(50 + 50);
</script>
</body>
</html>
document.write() after an HTML document will delete any existing HTML content:
<!DOCTYPE html>
<html>
<body>
<h1>Code Projects</h1>
<p>Projects, Tutorials and More </p>
<button type="button" onclick="document.write(50 + 50)">Click</button>
</body>
</html>