-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathscript.js
More file actions
85 lines (67 loc) · 2.91 KB
/
Copy pathscript.js
File metadata and controls
85 lines (67 loc) · 2.91 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* 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"
**/
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.outputRapName = function(inputName) {
let rapName = inputName.toString();
/* Generate random:
-Value to determine if and how to manipulate name.
ex.) 0 => do nothing, 1 => create acronym, 2 => use first letter only
-Booleans to determine which names to apply
-Index in both arrays to determine which name to apply
*/
let howToManipulateName = Math.floor(Math.random() * 3);
let applyFirstName = Math.random() >= 0.5;
let applyLastName = Math.random() >= 0.5;
let lastNameRandomIndex = Math.floor(Math.random() * this.last_names.length);
let firstNameRandomIndex = Math.floor(Math.random() * this.first_names.length);
console.log(firstNameRandomIndex);
if (howToManipulateName === 1) {
rapName = rapName.toUpperCase().split('').join('.') + '.';
}
else if (howToManipulateName === 2) {
rapName = rapName[0].toUpperCase();
};
if (applyFirstName) {
rapName = this.first_names[firstNameRandomIndex] + ' ' + rapName;
};
if (applyLastName) {
rapName = rapName + ' ' + this.last_names[lastNameRandomIndex];
};
//We want to apply at least one of the rap names. Apply both names if random returns double false.
if (!applyFirstName && !applyLastName) {
rapName = this.first_names[firstNameRandomIndex] + ' ' + rapName;
rapName = rapName + ' ' + this.last_names[lastNameRandomIndex];
}
return rapName;
}
$(document).ready(function () {
var engine = new Generator;
const playButton = document.getElementById('enter');
const inputForm = document.getElementById('user-input');
const noNameMessage = document.getElementById('no-name-alert');
const rapNameDisplay = document.getElementById('rap-name-display');
playButton.addEventListener('click', () => {
if (inputForm.value === '') {
noNameMessage.classList.remove('hidden')
rapNameDisplay.classList.add('hidden');
}
else {
rapNameDisplay.innerHTML = engine.outputRapName(inputForm.value);
noNameMessage.classList.add('hidden');
rapNameDisplay.classList.remove('hidden');
};
});
});