Exerpad
Exercise 6 · Chapter: String ManipulationRequired+50 XP

Word Search

Read a sentence and a search word. Print the position where the word first appears (using .indexOf()), and how many times it appears.

If the word is not found, .indexOf() returns -1.

Hint: to count occurrences, use the split trick: sentence.split(word).length - 1.

Example:

Input:

banana banana banana split
banana

Output:

0
3
Need a hint?
3 available · costs 5 XP each
javascript

Output
Run your code to see the output here.