bobo_bobkata

Untitled

Oct 9th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. function solve() {
  2. let options = document.getElementById("selectMenuTo");
  3. let binaryOption = document.createElement("option");
  4. binaryOption.textContent = "binary";
  5. options.appendChild(binaryOption);
  6. let hexOption = document.createElement("option");
  7. hexOption.textContent = "hexadecimal";
  8. options.appendChild(hexOption);
  9.  
  10. function convert() {
  11. let input = Number(document.getElementById("input").value);
  12. let result;
  13. if (options.value.toLowerCase() === "binary") {
  14. result = input.toString(2);
  15. } else if (options.value.toLowerCase() === "hexadecimal") {
  16. result = input.toString(16).toUpperCase();
  17. }
  18. document.getElementById("result").value = result;
  19. }
  20.  
  21. document.querySelector("#container > button").addEventListener('click', convert);
  22. }
Add Comment
Please, Sign In to add comment