Reputation: 13206
I have two values
startWidth = 500px
percentageWidth = 70%
I'd like to calculate the value of startWidth at when percentageWidth changes, for example if I wanted maxWidth, I'd be working with:
startWidth = ???px
percentageWidth = 100%
To calculate this mathematically is easy, I would just do:
70/100 = 500/x
70x = 50000
70x/70 = 50000/70
x = 714
How would I write this out as a JavaScript algorithm?
Upvotes: 0
Views: 107
Reputation: 25408
You can easily achieve the result as
const startWidth = 500;
const percentageWidth = 70;
const result = Math.round((startWidth * 100) / percentageWidth);
console.log(result);
Upvotes: 1