diff --git a/index.html b/index.html index 18f8b32..6e923ce 100644 --- a/index.html +++ b/index.html @@ -73,5 +73,6 @@

Rap Name Generator

+ diff --git a/js/app.js b/js/app.js new file mode 100644 index 0000000..3e8dc5b --- /dev/null +++ b/js/app.js @@ -0,0 +1,22 @@ +$(document).ready(function() { + setFormBindings(); +}); + +function setFormBindings() { + $('#enter').on('click', function() { + var user_input = $('#user-input').val(); + if (user_input) { + var engine = new Generator; + var name = engine.generateName(user_input); + $('.response').html(name).show(); + } else { + $('.error').show(); + } + }); + + $('#user-input').focus(function() { + $('.error').hide(); + $('.response').html("").hide(); + }); + +} diff --git a/js/script.js b/js/script.js index 2f2cff7..f60301b 100644 --- a/js/script.js +++ b/js/script.js @@ -1,5 +1,3 @@ - - /** * RAP NAME GENERATOR * The user will insert their first name and on click receive one of several @@ -13,20 +11,22 @@ **/ 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.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.generateName = function(actualName) { + var firstname = this.getRandomName(this.first_names); + var lastname = this.getRandomName(this.last_names); + var maybeMiddle = Math.floor((Math.random() * 2) + 0) == 0 ? actualName + " " : ""; + return firstname + " " + maybeMiddle + lastname; +} -//Add your codez here - - -$(document).ready(function() { - - var engine = new Generator; - //Add your codez here +Generator.prototype.getRandomPosition = function(array) { + return Math.floor((Math.random() * array.length) + 0); +} -}); +Generator.prototype.getRandomName = function(names) { + return names[this.getRandomPosition(names)]; +}