You return something only if items[c] == goal
inside the loop or if (c == items.length)
. This means that you return -1 at the last iteration but if you've got that far you've already iterated through the whole array. Replacing
if (c == items.length) // Searching element is absent
return (-1);
with just
return (-1);
should do the job