This sample program will ask the user to give a number and then our program will check and determine whether the given number by the user is a Palindrome or Not a Palindrome. I wrote this program using JavaScript.
Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
My mobile number here in the Philippines is 09173084360.
Sample Program Output
Program Listing
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Palindrome of Number in JavaScript</title>
<style>
body {
font-family:arial;
color:blue;
font-size:18px;
}
input[type="text"] {
display: block;
margin: 0;
width: 15%;
font-family: arial;
font-size: 18px;
appearance: none;
border-radius: 2px;
box-shadow: 10px 10px 7px #888888;
}
input[type="text"]:focus {
outline: none;
}
input[type=button] {
padding:12px 31px;
background:yellow; border:10px;
cursor:pointer;
-webkit-border-radius: 12px;
box-shadow: 10px 10px 7px #888888;
border-radius: 5px;
font-family: arial;
font-size: 18px;
}
</style>
</head>
<body bgcolor="lightgreen">
<script>
function start_palindrome() {
var revStr = "";
var str = document.getElementById("UserInput").value;
var i = str.length;
for(var j=i; j>=0; j--) {
revStr = revStr+str.charAt(j);
}
if(str == revStr) {
document.getElementById("result").innerHTML = "The Number " + str + " is Palindrome.";
}
else {
document.getElementById("result").innerHTML = "The Number " + str + " is Not a Palindrome.";
}
}
function clear_now()
{
document.getElementById('result').innerHTML="";
document.getElementById('userInput').value="";
document.getElementById('userInput').focus();
}
</script>
<b> Palindrome of Number in JavaScript </b> <br><br>
<form name="myform" action="">
<b>Give a Number </b><br><br>
<input type='text' id='UserInput' placeholder="enter number here" value='' size="5" required autofocus/>
<br><br>
<input type='button' onclick='start_palindrome()'
title="Click here to findout if the number in a palindrome or not." value='OK'/>
<input type='button' onclick='clear_now()' title="Click here to clear the textbox." value='CLEAR'/>
</form>
<br><br>
</body>
<div id = "result"></div>
</html>
No comments:
Post a Comment