Advertisement
Guest User

Untitled

a guest
May 24th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. function solve() {
  2.  
  3. let button = document.querySelector('#container > button')
  4. button.addEventListener('click', convertNumbers)
  5.  
  6. let convertSet = document.getElementById('selectMenuTo').children
  7. let firstSet = convertSet[0]
  8. firstSet.value = 'hexadecimal'
  9. firstSet.textContent = 'Hexadecimal'
  10. let optionn = document.createElement('option')
  11. optionn.value = 'binary'
  12. optionn.textContent = 'Binary'
  13. document.getElementById('selectMenuTo').appendChild(optionn)
  14.  
  15. function convertNumbers(ev) {
  16. let inputNumber = document.getElementById('input')
  17. let number = Number(inputNumber.value)
  18.  
  19. let event = document.getElementById('selectMenuTo').value;
  20. let result = ''
  21. if (event === 'hexadecimal') {
  22. result = number.toString(16).toUpperCase();
  23.  
  24. }
  25. else if (event === 'binary') {
  26.  
  27. result = number.toString(2)
  28.  
  29. }
  30.  
  31. let print = document.getElementById('result');
  32. print.value = result;
  33.  
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement