Advertisement
milovan7

Encode and Decode Messages

Apr 11th, 2021
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. function encodeAndDecodeMessages() {
  2. let textarea = document.getElementsByTagName('textarea');
  3. [...document.getElementsByTagName('button')].forEach(b => b.addEventListener('click', message));
  4.  
  5. function message(btn) {
  6. if (btn.target.textContent === 'Encode and send it') {
  7. let encoded = [...textarea[0].value].map(e => String.fromCharCode(e.charCodeAt(0) + 1)).join('');
  8. textarea[1].value = encoded;
  9. textarea[0].value = '';
  10. } else if (btn.target.textContent === 'Decode and read it') {
  11. let decoded = [...textarea[1].value].map(e => String.fromCharCode(e.charCodeAt(0) - 1)).join('');
  12. textarea[1].value = decoded;
  13. }
  14. }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement