• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaScript reverse integer (?)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having difficulty writing a program that needs to compute 2-6 digits reversed. For instance: 12 = 21 1456 = 6541, etc. This is what I have so far. Any hints are greatly appreciated. Thank You. email: j0kim025@uofl.edu
/*
<HTML>
<Head>
<title> Homework #5 part1 </title>
<script language = "javascript">

function begin()
{
var num = new Array(); // unlimited elements array
window.alert("work");

int num[0] = parseInt(window.prompt("Please Enter 2- 6 digits number",""));

if ( num[0] < 10 || num[0] > 999999)
{
int num[0] = parseInt(window.prompt("Please Re-Enter 2-6 digits number",""));
}
var n;
n = StrReverse("");

document.writeln(n);

}


</script>
</head>
<BODY><p> <h2> Click refresh to run it again </h2></p>
</body>
</html>*/
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have a forums devoted to JavaScript. I'll move this thread to there for you. Check for any followups in that forum.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, welcome to the ranch! And the HTML & JavaScript forum!

If you're not familiar with the ranch, you'll find we give you hints and invite you to do all the real work. We try not to just do homework, or real work, for folks. So ... I could imagine doing this two ways.

One: make a string from your user input, work your way through it one character at a time and add each character to a new string. Google for JavaScript string functions and see what you find.

Two: find a JavaScript math function that will give you just the "ones column" of your number. Make that your new result. Divide the original number by 10 to remove that "ones" value and repeat. I left out a critical bit of output processing but you'll find it quickly enough.

The ranch works really well when you post some code that almost works, so take a shot at either or both of those and show us what you make!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Please read this for more information.
 
reply
    Bookmark Topic Watch Topic
  • New Topic