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

Please Share: Tweet about this on TwitterShare on FacebookShare on Google+Share on RedditPin on PinterestShare on LinkedInDigg thisShare on StumbleUponShare on TumblrBuffer this pageShare on VKEmail this to someone

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

Leave a Reply

Your email address will not be published. Required fields are marked *