/javascript/robot-name/robot-name.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var Robot = function() {
  var alpha = 'ABCDEFGHIJKLMOPQRSTUVWXYZ';
  var numeric = '0123456789';

  // get a random alphabetic character
  function randomAlpha() {
    return alpha[Math.floor(Math.random() * alpha.length)];
  }

  // get a random numeric character
  function randomNumeric() {
    return numeric[Math.floor(Math.random() * numeric.length)];
  }

  // Reset the robot's name
  this.reset = function() {
    this.name = [1, 2].map(randomAlpha).join('') + [1, 2, 3].map(randomNumeric).join('');
  };

  // Give the robot a name on creation
  this.reset();
};


module.exports = Robot;

Comments


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