Credit card checker, not sure what a line of code does

Hello, I’m working through the credit card checker project. I can’t figure out what this line means in the solution to step 5, can someone please explain?

if (companies.indexOf(‘Discover’) === -1)

Hi @prelawfurball26
Welcome to the forums!
It checks if the string ‘Discover’ is NOT in the array ‘companies’.
indexOf() returns the index of an item in an array:

companies = ['Apple', 'Microsoft'];
companies.indexOf('Apple') // 0
companies.indexOf('Microsoft') // 1

If an item is not in the array, -1 is returned:
companies.indexOf('Discover') // -1

1 Like

Thank you very much!! That’s very helpful.

1 Like