OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

A Very SMALL function that have a BIG calculation Error

  • Thread starter Thread starter DrModeus
  • Start date Start date
D

DrModeus

Guest
I'm trying to run this calculating function, and it's works fine for the most part, until it shows the result of the calculation.


Code:
function dealCalc(pricePerUnity) {

    let userBudget = prompt("What's Your Budget?");
    let possibleAmount = userBudget / pricePerUnity ;
    let changeReturn = userBudget - ( possibleAmount * pricePerUnity );

    return alert("With that amount you can buy " + Math.floor(possibleAmount) + " Units \nand $" + changeReturn + " will be the Change!" );

}

dealCalc(3);

for example here it should output $1 as a change, but it output $0, and no matter how much price variation output it takes, the change is always $0. enter image description here Could someone Illuminate me please, thanks.

<p>I'm trying to run this calculating function, and it's works fine for the most part, until it shows the result of the calculation.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>function dealCalc(pricePerUnity) {

let userBudget = prompt("What's Your Budget?");
let possibleAmount = userBudget / pricePerUnity ;
let changeReturn = userBudget - ( possibleAmount * pricePerUnity );

return alert("With that amount you can buy " + Math.floor(possibleAmount) + " Units \nand $" + changeReturn + " will be the Change!" );

}

dealCalc(3);</code></pre>
</div>
</div>
</p>
<p>for example here it should output $1 as a change, but it output $0, and no matter how much price variation output it takes, the change is always $0.
<a href="https://i.sstatic.net/LhreiyBd.png" rel="nofollow noreferrer">enter image description here</a>
Could someone Illuminate me please, thanks.</p>
 

Latest posts

Top