Apoorv singhai Apoorv singhai - 7 months ago 12
HTML Question

Javascript code not showing any alert dialog

<html>
<head>
<title>BD Home page</title>
<style>
body{background-color:red;}
p{background-color:yellow;}
div{background-color:green; }
</style>
</head>
<body>
<script>
function mf()
{
Var x=new Date();
alert("Today is: "+x);
}
</script>
<button onclick="mf()">Click</button>
<div>Hellllllooooo</div>
<p>Hello this is html</p>
</body>
</html>


I am a beginner programmer.In the error code it says
mf
is not defined on line 1:1. I'm not able to understand that.

Is it important to enclose an alert dialog box under a function ?

Answer

Use var instead of Var. Javascript var keyword must be simple letters