Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although you don't explicitly say so, it appears that you're predicting a linear correlation between <code>screenWidth</code> and <code>percentageWidth</code>. If so, here's an example of code that you can put into a function for the result:</p> <pre><code>minScreenWidth = 320; maxScreenWidth = 1200; diffScreenWidth = maxScreenWidth - minScreenWidth; maxPercentageWidth = 98; // At screenWidth = 320 minPercentageWidth = 65; // At screenWidth = 1200 diffPercentageWidth = maxPercentageWidth - minPercentageWidth; screenWidth = 760; // Change this as needed. ratioScreenWidth = (screenWidth - minScreenWidth) / diffScreenWidth; percentageWidth = maxPercentageWidth - (ratioScreenWidth * diffPercentageWidth); // Since your example gave 82 as the desired result instead of 81.5, // I infer that you want the answer rounded. resultPercentageWidth = Math.round(percentageWidth); </code></pre> <p>@jantimon posted his answer first, with a very elegant one-line function (which I have upvoted). I kept working on this answer in the meantime because I had taken a different approach of breaking down the steps in the hope that it will help you analyze other math functions that you need to apply to JavaScript.</p> <p>I see that you are a new user. Welcome. And when you return to view the answers, please remember to mark one of them as correct (whichever was most useful to you), and to upvote any that were useful to you, if your reputation points allow it.</p> <p>Also, when you post questions in the future, please be aware that you're also expected to show examples of your own attempts and the results of those attempts.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload