Advertisement
Todorov_Stanimir

08. Encode and Decode Messages Exercise: DOM Manipulations

Oct 14th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function encodeAndDecodeMessages() {
  2.     const [encButton, decButton] = [...document.getElementsByTagName('button')];
  3.     let [senderTextArea, receiverTextArea] = document.getElementsByTagName('textarea');
  4.    
  5.     encButton.addEventListener('click', () => {
  6.         const encodeMessage = senderTextArea.value.split('').map(el => String.fromCharCode(el.charCodeAt() + 1)).join('');
  7.         senderTextArea.value = '';
  8.         receiverTextArea.value = encodeMessage;
  9.     });
  10.  
  11.     decButton.addEventListener('click', () => {
  12.         receiverTextArea.value = receiverTextArea.value.split('').map(el => String.fromCharCode(el.charCodeAt() - 1)).join('');
  13.     });
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement