Reverse of a Number
Reverse of a Number
<html>
<head>
<title>String Problem</title>
<script>
function reverseNum(num)
{
var reverse = 0;
while(num != 0)
{
reverse = reverse * 10;
reverse = reverse + num%10;
num = Math.trunc(num/10);
}
return reverse;
}
document.write(reverseNum(162));
</script>
</head>
<body>
</body>
</html>
2 number Palindrome
<html>
<head>
<title>String Problem</title>
<script>
function palin(number)
{
num=number;
var reverse = 0;
while(num != 0)
{
reverse = reverse * 10;
reverse = reverse + num%10;
num = Math.trunc(num/10);
}
return number===reverse;
}
document.write(palin(262));
</script>
</head>
<body>
</body>
</html>
3 Sum of Digits
<html>
<head>
<title>String Problem</title>
<script>
function digitSum(num) {
var sum=0;
while(num!=0){
sum += num % 10;
num = Math.floor(num/10);
}
return sum;
}
document.write(digitSum(512));
</script>
</head>
<body>
</body>
</html>
<html>
<head>
<title>String Problem</title>
<script>
function fact(num) {
if(num==1){
return 1; // Termination condition
}
else
return num*fact(num-1);
}
document.write(fact(6));
</script>
</head>
<body>
</body>
</html>
<html>
<head>
<title>Find the area and circumference of a circle</title>
</head>
<body>
<script>
function checkPrime(){
number=document.getElementById("num").value;
if (isPrime) {
document.write(' prime number');
} else {
document.write('not prime number');
}
}
}
</script>
<form name=form1>
Enter a number
<input type="text" id="num" size=10><br>
<input type="button" value="Check"
onClick='checkPrime();'>
</form>
</script>
</body>
</html>
<html>
<head>
<title>String Problem</title>
<script>
function fibonacci(n) {
var n1=0;
var n2=1;
var count=2;
var n3;
document.write(n1,n2);
while(count<n){
n3=n1+n2;
document.write(n3); //print current element
n1=n2;
n2=n3;
count++;
}}
document.write(fibonacci(6));
</script>
</head>
<body>
</body>
</html>
7 Armstrong number
<html>
<head>
<title>String Problem</title>
<script>
function armstrong(number)
{
var sum = 0;
var temp = number;
alert(number);
while (temp > 0)
{
var remainder = temp % 10;
sum += remainder * remainder * remainder;
temp = parseInt(temp / 10);
}
<html>
<head>
<title>Resume update Web Page</title>
</head>
<body '>
<div align="center">
<form method="post" action="#" >
<table width="90%" border=1 cellpadding="10px" >
<tr>
<td width="40%"><div align="right">Name of the
Candidate </div></td>
<td width='33%'><input name="cname" type="text" onkeypress="return onlyAlphabets(event,this);"
required></td>
</tr>
<td><div align="right">Email Address </div></td>
<td><input name="email" type="email" onblur="validateEmail(this);" required></td>
</tr>
<tr>
<td><div align="right">Mobile No. </div></td>
<td class="inputtext"> <input name="mobile" type="text" onkeypress="return isNumber(event)"
required></td>
</tr>
</table>
<p>
<input name="Submit" type="submit" class="inputtext" value="Submit">
<input name="Submit2" type="reset"
class="inputtext" value="Reset">
</p>
</form>
<script type='text/javascript'>
function isNumber(evt) {
evt = (evt) ? evt :window.event;
var charCode = (evt.which) ? evt.which :evt.keyCode;
if (charCode> 31 && (charCode< 48 || charCode>57))
{
return false;
}
return true;
}
</script>
<script type='text/javascript'>
function onlyAlphabets(e, t) {
try {
if (window.event) {
var charCode = window.event.keyCode;
}
else if (e) {
var charCode = e.which;
}
else { return true; }
if ((charCode> 64 &&charCode< 91) || (charCode>96 &&charCode< 123))
return true;
else
return false;
}
catch (err) {
alert(err.Description);
}}
</script>
<script type='text/javascript'>
function validateEmail(emailField){
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if (reg.test(emailField.value) == false)
{
alert('Invalid Email Address');
return false;
}
return true;
}
</script>
</body>
</html>