-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (53 loc) · 1.95 KB
/
Copy pathscript.js
File metadata and controls
65 lines (53 loc) · 1.95 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* RAP NAME GENERATOR
* The user will insert their first name and on click receive one of several
* possible outputs (i.e. Jill).
*
* "Inspectah Jill"
* "J.I.L.L. the Genius"
* "Chief Jill the Disciple"
* "Jill the Disciple"
* "Inspectah J"
**/
var rnd = function(array) {
return array[Math.floor(Math.random() * array.length)];
}
var capitalize = function(str) {
var ret = "";
for (var i = 0; i < str.length; i++) {
ret += str.charAt(i).toUpperCase() + ".";
}
return ret;
}
function Generator() {
/* Name Arrays: Customize names to change possible output */
this.last_names = ['the Chef', 'Digital', 'Wise', 'Knight', 'Wrecka', 'the Genius', 'the Zoo Keeper', 'the Monk', 'the Scientist', 'the Disciple', 'the Darkman', 'Pellegrino', 'the Ill Figure', 'Rocks The World', 'the Baptist',];
this.first_names = ['Inspectah', 'Masta', 'Poppa', 'Five Foot', 'Ghostface', 'Old Dirty'];
}
Generator.prototype.validate = function(name) {
return name.match(/[A-Z][a-z]*/);
}
Generator.prototype.generate = function(name) {
var formats = [
function(name) { return rnd(this.first_names) + " " + name; },
function(name) { return capitalize(name) + " " + rnd(this.last_names); },
function(name) { return rnd(this.first_names) + " " + name + " " + rnd(this.last_names); },
function(name) { return name + " " + rnd(this.last_names); },
function(name) { return rnd(this.first_names) + " " + name.charAt(0).toUpperCase(); }
];
var formatter = rnd(formats).bind(this);
return formatter(name);
}
$(document).ready(function() {
var engine = new Generator;
$('#enter').click(function() {
var name = $('#user-input').val();
if (engine.validate(name)) {
$('.response').text(engine.generate(name));
console.log($('.response').text());
$('.response').css('display', 'inline');
} else {
$('.error').css('display', 'inline');
}
});
});