Javascript to reverse a given number

By | July 19, 2017

This program uses a Javascript to reverse a given number. This is also known as the implementation of a palindrome. The program is quite simple. It asks you to enter a number and reverses the same for you. You can refer to the images for inputs and outputs.

 

We have explained two different methods to reverse a number here.

Suggested Read:

 

Input:

Javascript to reverse a given number

Pop-out box to enter an input number

Output 1:
Output of a reversed number

Output 2:

Output of a reversed number using javascript

The following video explains how to execute the javascript:

Alternative Method

There is an alternative method to reverse a given number using split(), reverse() and join() functions available in javascript. The following code explains this. 

 

Input:

Inputs to reverse a number using java script code

Diagram shows the pop-up box to input a number to be reversed

Output:

Output of a reversed number using java script code

Diagram shows the output of a reversed number

 

How to execute this script?

  1. Copy the code and save it in a text file with a .html extension.
  2. Open the file saved with a .html extension in a browser.
  3. You will be asked to enter a number/series and the result gets displayed on the same HTML page.
  4. To check for another number/series, refresh the page and again enter a new number. You can also refer to the video for easy understanding.

Please comment if you face any difficulties.




Author: Ravi Bandakkanavar

A Techie, Blogger, Web Designer, Programmer by passion who aspires to learn new Technologies every day. It has been 6 years since I have been publishing articles and enjoying every bit of it. I want to share knowledge and build a great community with people like you.

Suggested articles for you:

2 thoughts on “Javascript to reverse a given number

  1. Detlef

    Another way could be:

    function rev_num() {

    let num = prompt(“Enter the number to be reveresed :”, ” “);

    let str = num.toString().split(”).reverse().join(”);

    let rev = parseInt(str);

    document.write(“The given number is : ” +num+ ” The reversed number is : ” +rev+ “\n”);
    }

    Reply

Did it help? Comment here..