Answers for "javascript exercism.io bob solution"

0

javascript exercism.io bob solution

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;
Posted by: Guest on June-22-2020

Code answers related to "javascript exercism.io bob solution"

Code answers related to "Javascript"

Browse Popular Code Answers by Language