Manual of Javascript
Manual of Javascript
Manual of Javascript
<html>
<body>
<script type="text/javascript">
alert("Hello World");
</script>
</body>
</html>
Output
var dd = today.getDate();
var mm = today.getMonth()+1;
if(dd<10)
dd='0'+dd;
if(mm<10)
mm='0'+mm;
}
today = mm+'-'+dd+'-'+yyyy;
console.log(today);
today = mm+'/'+dd+'/'+yyyy;
console.log(today);
today = dd+'-'+mm+'-'+yyyy;
console.log(today);
today = dd+'/'+mm+'/'+yyyy;
console.log(today);
Output
11-10-2021
11/10/2021
10-11-2021
10/11/2021
<html>
<head>
<script>
function validateForm() {
let x = document.forms["myForm"]["fname"].value;
if (x == "") {
return false;
</script>
</head>
<body>
</form>
</body>
</html>
Output
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript</h2>
<p>Line-breaks Example in a popup box.</p>
<button onclick="alert('Hello\nHow are you?')">Please Try for line-breaks
Example</button>
</body>
</html>
Output
Solutions
1)Write a JavaScript program to swap the value of two variables without using a third
variable. Take the value of both variables from the user.
<html>
<head>
<title>Javascript</title></head>
<body>
<script type="text/javascript">
var x=parseInt(prompt("Enter first number"));
var y=parseInt(prompt("Enter second number"));
x = x+y ;
y = x -y ;
x = x -y ;
document.write("x =");
document.write(x);
document.write("<br>");
document.write("y =");
document.write(y);
</script>
</body>
</html>