Contact Validation
<html>
<head>
<title>Contact Validation</title>
</head>
<body>
<h1>Enter Your Information</h1>
<form action="">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required />
<br /><br />
<label for="phoneno">[Link] :</label>
<input type="text" id="phoneno" name="phoneno"
required />
<br /><br />
<button
type="button"
onclick="Validate([Link]('name').value,
[Link]('phoneno').value),
printResult(Validate([Link]('name').value,
[Link]('phoneno').value))"
>
Validate
</button>
</form>
<script>
function Validate(Name, Phoneno) {
if ([Link] == 0) {
alert("Name is Required");
return false;
}
if ([Link] == 0) {
alert("[Link] is Required");
return false;
if ([Link] != 11) {
alert("[Link] should be 11 digits");
return false;
if (!isAlphabetic(Name)) {
return "name should contain only letters";
if (!isNumeric(Phoneno)) {
return "[Link] should contain only numbers";
return "Validation Successful";
function isAlphabetic(str) {
return /^[A-Za-z]+$/.test(str);
function isNumeric(str) {
return /^[0-9]+$/.test(str);
function printResult(result) {
alert(result);
</script>
</body>
</html>
Factorial printed on Body
<html>
<head>
<title>Factorial of a number</title>
</head>
<body>
<h1>Factorial of a number</h1>
<p id="result"></p>
<script>
const numb = parseInt(prompt("Enter a number to
calculate Factorial :"));
const resultElem =
[Link]("result");
if (numb < 0) {
[Link] = "The number is
negative";
} else {
let factorial = 1;
for (let i = 1; i <= numb; i++) factorial = factorial
* i;
[Link] =
"The Factorial of " + numb + " is " + factorial;
}
</script>
</body>
</html>
Factorial using console
<html>
<head>
<title>Factorial</title>
</head>
<body>
<h1>Factorial</h1>
<script>
const number = parseInt( prompt("Enter a number
to calculate Factorial :")
);
if (number < 0) {
[Link]("Error! Factorial for negative number
does not exist.");
} else {
let factorial = 1;
for (let i = 1; i <= number; i++) factorial =
factorial * i;
[Link]("The Factorial of " + number + " is " +
factorial);
}
</script>
</body>
</html>