The conditions do not indicate wether or not you should or shouldn't count occourances of the word "world" within another string or not. When the split function encounters an instance of the word then the array will be contain two elements. if you don't encounter the word "world" then the size will be one. Therefore when subtracting one of the array size we get the amount of times the word appears in the text. This might not be the intended way to solve this but this should work if you include all substing occourances.