Advertisement
vdjalov

Converter

Jan 22nd, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. function solve() {
  2.  
  3. let menu = document.getElementById("selectMenuTo");
  4. menu.appendChild(document.createElement("option"));
  5. menu.appendChild(document.createElement("option"));
  6. menu.children[1].value = "binary";
  7. menu.children[1].textContent = "Binary";
  8.  
  9. menu.children[2].value = "hexadecimal";
  10. menu.children[2].textContent = "Hexadecimal";
  11. document.querySelector("button").addEventListener("click", () => {
  12.  
  13. let number = document.getElementById("input").value;
  14. let to = document.getElementById("selectMenuTo").value;
  15.  
  16. if(number && to == "hexadecimal"){
  17. document.getElementById("result").value = result =
  18. (+number).toString(16).toUpperCase();
  19. }else if (number && to == "binary"){
  20. document.getElementById("result").value = result =
  21. (+number).toString(2);
  22. }
  23. });
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement