Skip to content

Instantly share code, notes, and snippets.

@bogoreh
Last active March 12, 2021 05:55
Show Gist options
  • Select an option

  • Save bogoreh/2e888dd6c0f9e24abc5967396cd621d7 to your computer and use it in GitHub Desktop.

Select an option

Save bogoreh/2e888dd6c0f9e24abc5967396cd621d7 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Challenge: Loopy language</title>
</head>
<body>
<h1>All about Pig Latin</h1>
<p>Pig Latin is a language game in which words in English are altered. The objective is to conceal the meaning of the words from others not familiar with the rules. The reference to Latin is a deliberate misnomer, as it is simply a form of jargon, used only for its English connotations as a strange and foreign-sounding language.</p>
<p>The origins of Pig Latin are unknown. A youthful Thomas Jefferson wrote letters to friends in Pig Latin.</p>
<p>For words that begin with consonant sounds, the initial consonant or consonant cluster is moved to the end of the word, and "ay" is added.</p>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'></script>
<script>
// Takes a string and returns Pig Latin version of it
var toPigLatin = function(str) {
if (!str.replace) {
return 'ERROR: Expected a string!';
}
return str.replace(/\b(\w)(\w+)\b/g, '$2-$1ay').toLowerCase();
};
// Iterate through each paragraph, call the toPigLatin function on it
var $paragraphs = $("p");
for (var i = 0; i < $paragraphs.length; i++) {
var element = $paragraphs[i];
var $paragraph = $(element);
$paragraph.text(toPigLatin($paragraph.text()));
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment