You can normalize the number by getting the percentage of ownPercentage
out of 90
(your total number (100
) minus your start number (10
)) and then multiplying by your total number (100
):
var ownPercentage = (Math.random()*90)+10;
var ownPercentageWidth = ((ownPercentage - 10) / 90) * 100;
$('#ownLeft').width(ownPercentageWidth + '%');
$('#ownRight').width(100-ownPercentageWidth + '%');
10
would give 0%
width, 55
would give 50%
width and 100
would give 100%
width.
if ownPercentage
was 10
, this would give:
> ((10 - 10) / 90) * 100
> (0 / 90) * 100
> 0 * 100
> 0
..and if it was 55
:
> ((55 - 10) / 90) * 100
> (45 / 90) * 100
> 0.5 * 100
> 50
..and if it was 100
:
> ((100 - 10) / 90) * 100
> (90 / 90) * 100
> 1 * 100
> 100