Advertisement
Guest User

NumberConvertor

a guest
May 24th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.    let sendButton = document.getElementById("send");
  4.    let inputForm = document.getElementById("input");
  5.    let selectMenuFrom = document.getElementById("selectMenuFrom");
  6.    let selectMenuTo = document.getElementById("selectMenuTo");
  7.    let resultOutputForm = document.getElementById("result");
  8.  
  9.    let optionElement = document.getElementsByTagName("option")[1];
  10.    optionElement.value = "binary";
  11.    optionElement.textContent = "Binary";
  12.    
  13.    let createOptionElement = document.createElement("option");
  14.    createOptionElement.value = "hexadecimal";
  15.    createOptionElement.textContent = "Hexadecimal";
  16.  
  17.    selectMenuTo.appendChild(createOptionElement);
  18.    
  19.    sendButton.addEventListener("click", function (){
  20.       let inputFormValue = Number(inputForm.value);
  21.       let valueOfForm = selectMenuTo.value;
  22.      
  23.       if (valueOfForm === "binary") {
  24.          let numberToBinary = inputFormValue.toString(2);
  25.          resultOutputForm.value = numberToBinary;
  26.       } else if (valueOfForm === "hexadecimal"){
  27.          let numberToHexadecimal = inputFormValue.toString(16);
  28.          resultOutputForm.value = numberToHexadecimal.toUpperCase();
  29.       }
  30.        
  31.    });
  32.    
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement