Avatar of sfareed
sfareedFlag for United States of America

asked on 

Create palindrome in JavaScript by using parseInt

A palindrome is a number or a text phrase that reads the same backward and forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write a script that reads in a five-digit integer and determines whether it is a palindrome. If the number is not five digits long or is not a valid number, output XHTML text that displays an alert dialog indicating the problem to the user. Allow the user to enter a new value after dismissing the alert dialog. Continue the whole process until the user enters “stop”.
Hint:
Given a number say 12345:
One solution to find out values for all the digits
var startNumber = parseInt (12345/10000) will give you the first digit 1
var endNumber =12345%10  will give you last digit 5

After the comparison – if they are the same and you need to continue

var remaingNumber = parseInt ((12345 – startNumber *10000)/10 ) will give you the remaining number needs to be processed 234
JavaScript

Avatar of undefined
Last Comment
dakyd
Avatar of sfareed
sfareed
Flag of United States of America image

ASKER

Create palindrome
Avatar of dakyd
dakyd

Looks like homework ... we're not allowed to actually do it for you, but if you show us what you have so far, we can help you figure out what you're doing wrong/still need to do.
Avatar of sfareed
sfareed
Flag of United States of America image

ASKER

Please help me out I have done so far as following
But my this line giving me an error "  var second=parseInt ((12345– startNumber *10000)/10 ) "
Here is the code


var d=window.prompt ("Enter the 5 digit number or stop to proecess the stop ", "0");
 var strNumber= parseInt(d/10000)
 var endNumber=parseInt(d%10)
 var second=parseInt ((12345– startNumber *10000)/10 )
 
 if (strNumber ==endNumber)
{
document.write("<b>Pend Number</b><br />")

document.write("The first Number is " +strNumber+ "<br />")
document.write("The end Number  is " +endNumber+ "<br />")
document.write("The  second number is " +second+ "<br />")
}
else
{
document.write("<b>Good Bye you put a wrong number</b>")
}
 
</script>
ASKER CERTIFIED SOLUTION
Avatar of dakyd
dakyd

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo