My Index Of - clarification

So I was just on hacker rank (Javascript) doing a problem called ‘MyIndexOf’. According to directions:
‘given a string and a search term, returns the index of the search term if it exists in the given string, or -1 if it does not’

Then an example (and test case) was:
myIndexOf(‘balloons are fun’, ‘all’) // -> 1
myIndexOf(‘where in the world is’, ‘Carmen Sandiego’) // -> -1

The second example makes sense to me, but the first one did not and it messed my whole head up.

How is the answer 1 when the word ‘all’ is not in the phrase ‘balloons are fun’. I mean yes, ‘balloon’ has the word all in it but is not an exact match, nor is ‘balloons’ at index 0. Is it because the word ‘all’ starts at index 1 of balloon? That’s still confusing to me.
Can someone explain this to me, or is my confusion just?

Thank you!

The string “all” starts at index 1 of the string “balloons are fun”, yes.

sure is an exact match, the search term is all, balloons contain thsoe three letters in that same order with no others in between

1 Like