Skip to content
Advertisement

The Next Palindrome number

I am beginner in programming, So can you please tell me what’s wrong with my code?

I want to print next palindrome number if the number entered by the user (n) is not palindrome

JavaScript

Advertisement

Answer

There are two problems with your code.

1) Your “for i in range” loop calculates the reverse of the temp variable, but you don’t change the temp variable’s value. You do

JavaScript

So you’re making 10 iterations with one and the same value.

2) Ten iterations might not be enough to find a palindrome. Keep going until you find a palindrome.

Working code:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement