Javascript Practical 1
1)To accept integer and display the result by multiplying it with 3.
<!DOCTYPE html>
<html>
<body>
<script>
var n = prompt("Enter an integer:");
alert(n * 3);
</script>
</body>
</html>
2) To accept two integers and display larger number of them
<!DOCTYPE html>
<html>
<body>
<script>
var a = prompt("Enter first integer:");
var b = prompt("Enter second integer:");
if (a > b)
alert("Larger number is: " + a);
else
alert("Larger number is: " + b);
</script></body></html>
3) To check whether, user entered number is positive or negative
<!DOCTYPE html>
<html>
<body>
<script>
var n = prompt("Enter a number:");
if (n >= 0)
alert("Number is Positive");
else
alert("Number is Negative");
</script>
</body>
</html>
Javascript Practical 2
1) To accept two positive or negative numbers and check whether
they are equal or not.
<!DOCTYPE html>
<html>
<body>
<script>
var a = prompt("Enter first number:");
var b = prompt("Enter second number:");
if (a == b)
alert("Both numbers are Equal");
else
alert("Both numbers are Not Equal");
</script>
</body>
</html>
2) To accept number and display square of it.
<!DOCTYPE html>
<html>
<body>
<script>
var n = prompt("Enter a number:");
alert(n * n);
</script>
</body></html>
3)To check whether the accepted integer is multiple of 3 or multiple of
7.
<!DOCTYPE html>
<html>
<body>
<script>
var n = prompt("Enter an integer:");
if (n % 3 == 0)
alert("Number is a multiple of 3");
else if (n % 7 == 0)
alert("Number is a multiple of 7");
else
alert("Number is not a multiple of 3 or 7");
</script></body></html>
Javascript Practical 3
1) To accept string and calculate its length.
<!DOCTYPE html>
<html>
<body>
<script>
var str = prompt("Enter a string:");
alert("Length of string is: " + [Link]);
</script></body></html>
2) To accept string and display it into lowercase and uppercase.
<!DOCTYPE html>
<html>
<body>
<script>
var str = prompt("Enter a string:");
alert("Lowercase: " + [Link]());
alert("Uppercase: " + [Link]());
</script>
</body>
</html>
3) To check whether the length of string is 4 or greater
<!DOCTYPE html>
<html>
<body>
<script>
var str = prompt("Enter a string:");
if ([Link] >= 4)
alert("Length of string is 4 or greater");
else
alert("Length of string is less than 4");
</script>
</body>
</html>