SHARE
TWEET

Untitled

a guest May 25th, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.     let convertBtn = document.querySelectorAll('#container button')[0];
  4.     let toList = document.querySelectorAll('#selectMenuTo')[0];
  5.     let optionToList = document.querySelector('#selectMenuTo option');
  6.     let inputOfUser = document.querySelector('#input');
  7.     let result = document.querySelector('#result');
  8.  
  9.     addElementToList('binary', 'Binary');
  10.     addElementToList('hexadeicmal', 'Hexadeicmal');
  11.  
  12.     function addElementToList(valueOfNewProp, contentOfNewProp) {
  13.         let newElement = optionToList.cloneNode(true);
  14.         newElement.value = `${valueOfNewProp}`;
  15.         newElement.textContent = `${contentOfNewProp}`;
  16.         toList.appendChild(newElement);
  17.     }
  18.  
  19.     convertBtn.addEventListener('click', convert);
  20.  
  21.     function convert() {
  22.         if (toList.value === 'binary') {
  23.             convertBinary(inputOfUser.value)
  24.         } else if (toList.value === 'hexadeicmal') {
  25.             convertHexadeicmal(inputOfUser.value)
  26.         }
  27.     }
  28.  
  29.     function convertBinary(userValue) {
  30.         let binary = parseInt(userValue, 10);
  31.         result.value = binary.toString(2);
  32.     }
  33.  
  34.     function convertHexadeicmal(userValue) {
  35.         result.value = Math.abs(userValue).toString(16).toUpperCase();
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top