javascript exercism.io bob solution

JavaScript
var Bob = function() {
  return {
    hey: function(input) {
      // Remove leading or trailing spaces just in case.
      input = input.trim();
      
      // Check for silence (empty string or spaces which would be removed by trim above).
      if (input === '') {
          return 'Fine. Be that way!';
      }
      
      // Regular expression to test if there are any letter (alphabetic) characters
      // in input string. (Regex excludes non-alpha characters.)
      regex = /[^\W\d_]+/g;
      
      // Test for alpha characters and SHOUTING.
      if (regex.test(input) && input === input.toUpperCase()) {
        return 'Whoa, chill out!';
      }
      
      // Check for a question.
      if (input.charAt(input.length-1) === '?') {
          return 'Sure.';
      }
      
      // All other cases:
      return 'Whatever.';
    }
  };
};
module.exports = Bob;
Source

Also in JavaScript: