title: Changing marker colour based on property in Leaflet
body: <p>I'm aiming to have my markers in three different colours depending on their <code>rating</code> property. I have seen a similar post where an object was used to define the colours. Each marker has a <code>rating</code> attribute between 1 and 5. </p>
  
  <p>I was thinking of using a else if statement e.g</p>
  
  <pre><code>if (rating &lt; 3) {
      markerColor: 'red'
  } else if (rating = 3 ) {
      markerColor: 'orange'
  } else {
      markerColor: 'green'
  }
  </code></pre>
  
  <p>I am creating my markers as follows:</p>
  
  <pre><code>for (var i = 0; i &lt; data.length; i++)   {
  
      var customOptions = {
          'maxWidth': '500',
          'className' : 'custom'
      };
  
      //Custom icon
      var blueMarker = L.AwesomeMarkers.icon({
          markerColor: 'blue'
      });
  
      //Create markerLocation variable    
      var markerLocation = new L.LatLng(data[i].lat, data[i].lon);
  
      //Create marker variable
      var marker = new L.Marker(markerLocation, {icon: blueMarker});
  
      marker.bindPopup("&lt;p&gt;&lt;h2&gt;Rating:&lt;/h2&gt; " + data[i].rating_value,
                       customOptions);
  }
  </code></pre>
  
  <p>Would the else if statement be used when assigning the blueMarker variable?</p>
  
  <p>Thanks</p>
  
  <p>I used </p>
  
  <pre><code>  var = customColour = "green";
  
    if (data[i].rating_value &lt; 3)
      customColor = "red";
    else if (data[i].rating_value === 3)
      customColor = "orange";
  
  //Create custom icon
    var customMarker = L.AwesomeMarkers.icon({
    markerColor: customColour
    });
  
  //Create markerLocation variable    
    var markerLocation = new L.LatLng(data[i].lat, data[i].lon);
  
  //Create marker variable
    var marker = new L.Marker(markerLocation, {icon: customMarker});
  </code></pre>
  
  <p>However the AwesomeMarkers plugin only accepts colours, so I dont think using customColour worked. <a href="https://github.com/lvoogdt/Leaflet.awesome-markers" rel="nofollow noreferrer">https://github.com/lvoogdt/Leaflet.awesome-markers</a>. Thanks</p>