SHARE
TWEET

numberconversion

Aliendreamer Jan 20th, 2019 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let button=document.getElementsByTagName("button")[0];
  3.     button.addEventListener("click",()=>MakeMath());
  4.     const binaryHolder="binary";
  5.     const hexaDecimal="hexadecimal";
  6.     function MakeMath(){
  7.        let numberToConvert=Number(document.getElementById("input").value);
  8.        let systemToConvertTo=document.getElementById("selectMenuTo").value;
  9.        let  result;
  10.        
  11.        if(systemToConvertTo==binaryHolder){
  12.             result=numberToConvert.toString(2);            
  13.        }
  14.      
  15.        if(systemToConvertTo==hexaDecimal){
  16.          result=("0"+(numberToConvert.toString(16))).slice(-2).toUpperCase();
  17.        }
  18.        if(result){
  19.            let resultDiv=document.getElementById("result");
  20.            resultDiv.value=result;        
  21.        }
  22.     }
  23. }
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
 
Top