When I compare part of an array to part of another I get "Error"

88 Views Asked by At

This is written in javascript using he cloud IDE of smart face. But for some reason I can compare parts to lists/arrays. Please help!! Any advice or input would be greatly appreciated!

var dropC = "green red blue blue blue"
var dropColors = dropC.split(" ");
var colors = ["green", "blue", "red", "yellow"];
var l = 1
var dropColor;

if (dropColors[l] == colors[0]) {
  dropColor = "green";
} else if (dropColors[l] == colors[1]) {
  dropColor = "blue";
} else if (dropColors[l] == colors[2]) {
  dropColor = "red";
} else if (dropColors[l] == colors[3]) {
  dropColor = "yellow";
} else {
  dropColor = "Error";
}
alert(dropColor);

Regardless the value of l the result is always "Error".

0

There are 0 best solutions below