/javascript/bob/bob.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var Bob = function() {};

Bob.prototype.hey = function(input) {
  if (input.match(/[A-Z]/) && input == input.toUpperCase()) {
    return 'Whoa, chill out!';
  }

  if (input.slice(-1) == '?') {
    return 'Sure.';
  }

  if (input.trim() === '') {
    return 'Fine. Be that way!';
  }

  return 'Whatever.';
};

module.exports = Bob;

Comments

I think you could use else if instead of plain if so that the code can skip directly to the return statement once it finds a match!

AkA84 commented 7 January 2015 at 20:51 UTC

Hmm, I don't know - I think I prefer the early returns, it saves on a variable assignment (I wouldn't use both else if and early returns together)

helenst commented 9 January 2015 at 11:03 UTC

You're not logged in right now. Please login via GitHub to comment