Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Sorry for not following the terms here. Now I got to reverse but my problem I have to convert the while into do while can you help me.. Here's the code


XML
<html>
<head></head>
 <script type ="text/javascript">

<html>
<head></head>
 <script type ="text/javascript">


	       var reverse = 0; 
                 var n = prompt("Enter reverse numbers: "); 
		while (n != 0) { 
                reverse = reverse * 10;
		reverse = reverse + parseInt(n%10); 
		n = parseInt(n/10); } 
		document.write(" The reverse of the number: "+reverse);	


</script>
<body>

</body>
</html>

and here's what I've done so far

var reverse = 0;
		
			
		var n = prompt("Enter reverse numbers: "); 
		
do {
reverse = reverse * 10;
		reverse = reverse + parseInt(n%10); 
		n = parseInt(n/10); } 
		document.write(" The reverse of the number: "+reverse);

}while(n != 0);}


When I run this it output a blank. Don't know where I got mistake. 
Thanks to your help God bless
Posted
Updated 7-Aug-15 20:49pm
v2

1 solution

You cannot use mathematical operations on strings (parseInt(n%10)). You first need to convert the entire input string into an integer and then do the reverse operation. Alternatively you could just split the string into an array of characters and then reverse them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900