Nothing special - indexOf()
will return -1 in case of mismatch, not false or zero because we need zero just in case that was catched by QA.
Honestly in ES6/ES7 world we already have includes()
that will fit better in our case - we don't need to know substring position, just is it included or not. Or maybe RegExp
with special flag that will ignore case.
But because of initial requirenments my answer is:
function validateString(str) {
if (str.toLowerCase().indexOf('superman') === -1) {
throw new Error('String does not contain superman');