Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<head> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
Expand Down Expand Up @@ -69,8 +68,8 @@ <h1>Rap Name Generator</h1>


</div>
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="js/google-code-prettify/prettify.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</body>
Expand Down
84 changes: 73 additions & 11 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@


/**
/**
* RAP NAME GENERATOR
* The user will insert their first name and on click receive one of several
* possible outputs (i.e. Jill).
Expand All @@ -11,22 +9,86 @@
* "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'];
/* 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'];

}
var last_names = this.last_names;
var first_names = this.first_names;

this.generate = function(name) {
rap_name = []
rap_name.push(first_name(), middle_name(name), last_name());

shuffled = shuffle(rap_name).join(' ');
return shuffled
}

function last_name() {
var index = getRandomIndex(last_names);
return last_names[index];
}

function first_name() {
var index = getRandomIndex(first_names);
return first_names[index];
}

function middle_name(name) {
var options = [];

// .charAt() and .toUpperCase() were throwing expections
// with normal this.original_name. String() encasing seemed to fix it
this.original_name = String(name);

//Add your codez here
options.push(this.original_name);
options.push(this.original_name.charAt(0).toUpperCase());
options.push(this.original_name.toUpperCase().split('').join('.'));

var index = getRandomIndex(options);
return options[index]
}

function shuffle(array) {
var currentIndex = array.length, tempVal, randomIndex;

// While there remain elements to shuffle
while (0 !== currentIndex) {
// Pick a remaining element
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;

// Swap it
tempVal = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = tempVal;
}

return array;
}

function getRandomIndex(array) {
return Math.floor(Math.random() * array.length);
}
}

$(document).ready(function() {
var engine = new Generator;

$("#enter").click(function() {

if ($("#user-input").val() !== "") {
$(".error").hide();

var engine = new Generator;
//Add your codez here
var original_name = $("#user-input").val();
var rap_name = engine.generate(original_name)
$(".response").text(rap_name).show();
} else {
$(".error").show();
$(".response").hide();
}
});

});