Skip to content

Instantly share code, notes, and snippets.

@cferdinandi
Created June 5, 2023 14:55
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 cferdinandi/0cdd9adf13a24995ccb6827123c8a141 to your computer and use it in GitHub Desktop.
Save cferdinandi/0cdd9adf13a24995ccb6827123c8a141 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Secret Message</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<script>
let message = 'Hey there friend! How are you today?';
/**
* Create a secret message from a string
* @param {String} str The string to encode
* @return {String} The encoded string
*/
function createCode (str) {
let words = str.split(/[\s]+/g);
let encoded = words.map(function (word) {
return word.split('').reverse().join('');
});
return encoded.join(' ');
}
let secret = createCode(message);
console.log(secret);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment