Ask the user for a phrase and then print out a version of that phrase with the letters reversed back to front. For an example click here The magic here is done with arrays, a list of similar elements that can be accessed by their location in the array. For example, you might have an array of cars, declared like this:
var cars [];
document.write( cars[2] ); One approach to Reverse-a-Phrase is to use two arrays, one to take all the letters from the initial phrase, and then to walk thru this array back to front, copying the letters, one by one, into the second array. There are other ways to do this, see if you can try different algorithms. NOTE: This is the most common question asked on technical interviews - "Write a program to reverse a phrase" |
Directions |
||
|