This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# JavaScript Coding Exemplar: | |
### Question 1 | |
The issue with the function is that when the string begins with 'superman', the indexOf is 0, which is a 'falsy' value. The if statement returns false for this 0 and because of this, the error is thrown. | |
The indexOf for a string without 'superman' is -1, so a better function in this case would be: | |
``` | |
const validateString = (str) => { | |
if(str.toLowerCase().indexOf('superman') === -1) |