Skip to main content
2 of 2
added 218 characters in body
svidgen
  • 311
  • 2
  • 7

JavaScript

function pick(names) {
  var r = Math.floor(Math.random * names.length);
  for (var i = 0; i < names.length; i++) { if (i >= r) { break; } }
  return names[i-1];
}
alert(pick(["John", "Jeff", "Emma", "Steve", "Julie"]));

The gods have spoken, Julie. Don't fight destiny.

Like all fearlessly awesome languages, JavaScript not only forgoes an exception and returns a value when you "invoke" a function without parenthesis; but also when you multiply by something that is not a number.

svidgen
  • 311
  • 2
  • 7