Skip to content
Open
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
52 changes: 42 additions & 10 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


/**
* RAP NAME GENERATOR
* The user will insert their first name and on click receive one of several
Expand All @@ -12,21 +10,55 @@
* "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'];
// add a .sample() function to our array objects
Array.prototype.sample = function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

// returns a random element from the array
return this[Math.floor(Math.random() * this.length)];
}

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.rapName = function(basicName) {
// generate random number between 1 and 2
var x = Math.floor((Math.random() * 2) + 1);

//Add your codez here
// decide to add first name or last name
if (x == 2) {
return basicName + " " + this.last_names.sample();
} else {
return this.first_names.sample() + " " + basicName;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the case for B.R.Y.O.N. the Chef

};

Generator.prototype.validInput = function(input) {
var pattern = /^ *[a-zA-Z]/g;
// return true if input contains numbers or is empty
return pattern.test(input);
}

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

var engine = new Generator;
//Add your codez here
$('#enter').on('click', function() {
var userName = $('#user-input').val();

// test user input and display rap name or error
if (engine.validInput(userName)) {
$('.error').hide();
$('.response').text(engine.rapName(userName)).show();
} else {
$('.response').hide();
$('.error').show();
}
});
});