Skip to content

Instantly share code, notes, and snippets.

@KatieK2
Created August 22, 2013 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KatieK2/6309512 to your computer and use it in GitHub Desktop.
Save KatieK2/6309512 to your computer and use it in GitHub Desktop.
Reverse the String
<h1>Reverse the String</h1>
<h2>My Awesome String</h2>

Reverse the String

Interview Question: Write a JavaScript function to reverse / flip an incoming string.

A Pen by KatieK on CodePen.

License.

$(function() {
var theString = $("h2").text();
var revString = "";
for (var i=theString.length; i>0; i--)
{
revString = revString + theString.charAt(i-1);
}
$("h2").text(revString);
});
h1, h2, p { margin: 1rem; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment