Write a program to check whether a given number is a
palindrome or not?
Answer Posted / upendar
This Script checks the given number as well as string is palindrome or not
<html>
<body>
<script type="text/javascript">
function checkPalindrome() {
var revStr = "";
var str = document.getElementById("str").value;
var i = str.length;
for(var j=i; j>=0; j--) {
revStr = revStr+str.charAt(j);
}
if(str == revStr) {
alert(str+" -is Palindrome");
} else {
alert(str+" -is not a Palindrome");
}
}
</script>
<form >
Enter a String/Number: <input type="text" id="str" name="string" /><br />
<input type="submit" value="Check" onclick="checkPalindrome();"/>
</form>
</body>
</html>
Is This Answer Correct ? | 437 Yes | 107 No |
Post New Answer View All Answers
discuss scoping in javascript?
Does javascript support automatic type conversion?
What is callback in javascript?
What are the features of javascript?
How do I view javascript in chrome?
What is an immediately-invoked function expression?
What is encodeuri() function?
What can I build with javascript?
What is the difference between ‘let’ and ‘const’?
How to get the last index of a string in javascript?
How do I open javascript in chrome?
What javascript method would convert the string “20” to an integer (on the fly) so “20” + 20 = 40?
What value does prompt() return if the user clicked the cancel button?
How do I use javascript to password-protect my web site?
How to define name function in javascript?