Learning Web App Development

by Semmy Purewal

indexOf off-by-one error

page 219

20 Apr 2014

There is a slight error in the code that determines if a tweet contains the word awesome. Specifically, on pages 219 and 221, the code that says

if (tweet.text.indexOf("awesome") >= -1) {

should not have the equals. In other words, it should read

if (tweet.text.indexOf("awesome") > -1) {

If indexOf returns -1, then it means it didn’t find the word. This is actually correct in the code found in our Github repository.

This was caught by an incredibly sharp reader named Nick Litwin!

Thanks, Nick!