Created
June 5, 2023 14:55
-
-
Save cferdinandi/0cdd9adf13a24995ccb6827123c8a141 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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