0

It has been some time since I coded. I have gotten the code to work. The math is correct when the output shows, but the input only allows whole numbers. If I try putting in a decimal, the results won't show anything. I think the parse int lines are wrong but I'm not sure what to replace it with. Thank you! The equation is (bitcoin market cap / by target coin market cap) * current coin price = max price per one coin

 var numOne, numTwo, numThree, res, temp;
    function crypto()
    {
      numOne = parseInt(document.getElementById("one").value);
      numTwo = parseInt(document.getElementById("two").value);
      numThree = parseInt(document.getElementById("three").value);
      if(numOne && numTwo && numThree)
      {
        temp = document.getElementById("res");
        temp.style.display = "block";
        document.getElementById("calc").value = res;
        res = (numOne / numTwo) * numThree;
      }
    }
    <p id="input">Enter Bitcoin Marketcap: <input id="one">
    <br/><br/>
    Enter Target Marketcap: <input id="two"></p>
    Enter Current Price per One Target Coin: <input id="three"></p>
    <p><button onclick="crypto()">Calculate max price per one cryptocoin</button></p>
    <p id="res" style="display:none;">
    Price Per Coin Result = <input id="calc"><br/><br/>
    
CodeBug
  • 1,649
  • 1
  • 8
  • 23
  • 1
    change your `parseInt` to `Number` or `parseFloat` - `parseInt` will only return whole integers – Kinglish Jun 05 '21 at 05:56
  • 1
    `document.getElementById("calc").value = res;` add this after `res = (numOne / numTwo) * numThree;` – CodeBug Jun 05 '21 at 05:56

0 Answers0