So I am trying to find if a certain number is in between two other numbers.
I have an array of 'Bands' and their 'Color' codes.
What I want is, if the 'co2Amount' is in between one of the array 'Band' values, then it displays that bands 'Color' code.
So the code below should output '#c8ff5c' as its the color code for any co2 amount between 101 and 200.
Heres what I have:
var co2Bands = [ {Band:"0-100",Color:"#deff9e" }, {Band:"101-200",Color:"#c8ff5c"}, ];
var co2Amount = "150";
$.each(co2Bands, function() {
var bandNumber = this.Band.split('-');
if (bandNumber[0] >= co2Amount && bandNumber[1] <= co2Amount) {
$('#co2ColorCode').append(this.Color+'<br>');
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="co2ColorCode"></div>
co2Bandsarray? If so I'd suggest splittingBandin to two separate integers, min and max