8. Java Script Method and Event Handler.

Sahil Sahani
0

 8.Java Script Method and Event Handler.


8A) Using Java script to demonstrate the use of date object.

CODE:

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>Using new Date()</h2>
<p>Create a new date object with the current date and time:</p>
<p id="demo"></p>
<script>
const d = new Date();
document.getElementById("demo").innerHTML = d;
</script>
</body>
</html>

    

OUTPUT:




8B) Using Java script to demonstrate the use of math object.

CODE:

<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Math.round()</h2>
<p>Math.round(x) returns the value of x rounded to its nearest integer:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Math.round(25.6);
</script>
</body> </html>

    

OUTPUT:




8C) Java script to demonstrate the use of onload event & onclick event.

CODE: ONLOAD EVENT:-

<!DOCTYPE html>
<html>
<body onload="myFunction()">
<h1>Hello World!</h1>
<script>
function myFunction() { alert("Page is loaded");
}
</script>
</body></html>

    

OUTPUT:





CODE:ONCLICK EVENT:-

<!DOCTYPE html>
<html>
<body>
<h2>JavaScript onclick Event</h2>
<p id="demo"></p>
<button onclick="document.getElementById('demo').innerHTML=Date()">The time is?</button>
</body>

    

OUTPUT:



Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)