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
What is javascript namespacing?
How to port a GUI application onto Web
Why do we need hoisting in javascript?
What is lazy loading in javascript?
What are exports & imports?
What is the importance of javascript? Expalin
What is console.log()?
How to disable an html object ?
Which javascript framework is in demand?
How do you change the style/class on any element using javascript?
What value does prompt() return if the user clicked the cancel button?
Why javascript is called as script for all browsers?
How to modify the url of the page without reloading the page?
What is the function of deferred scripts?
How are event handlers utilized in javascript?