HTML code to reverse given number using javascript

By | July 5, 2015

Parameter: Any number
Output: The number with its digits in the reverse order

 

 

<html>

<--script type ="text/javascript">
function rev_num()
{
var num = prompt("Enter the number to be reveresed :", " ");
var n= num;
var rev = 0, rem;
while (n>0)
{
rem = n % 10;
rev = rev * 10 + rem ;
n = Math.floor(n/ 10);
}
document.write("The given number is : " +num+ " <br/> The reverse of the given number is : " +rev+ "\n");
}


<–/script>
<body style=”background-color : grey” on-Load= “rev_num();”> //on-Load should be onload

<body>
</html>

Output:
Enter the number to be reversed : 671(prompt appears)
The reverse of the given number is : 176





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 read for you:

One thought on “HTML code to reverse given number using javascript

Did it help? Comment here..