diff --git a/js/script.js b/js/script.js index 2f2cff7..060a680 100644 --- a/js/script.js +++ b/js/script.js @@ -15,18 +15,50 @@ 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']; + this.last_names = ['The Dill', '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 = ['Fella', 'Inspectah', 'Masta', 'Poppa', 'Five Foot', 'Ghostface', 'Old Dirty']; + this.generate = function() { + var firstName = this.first_names[generateRandomindex(this.first_names)]; + var lastName = this.last_names[generateRandomindex(this.last_names)]; + + return firstName + " " + lastName; + } +} + +function generateRandomindex(array) { + return Math.floor(Math.random() * array.length); } +$(document).ready(function() { -//Add your codez here + var engine = new Generator; + + $("#enter").click(function() { + var name = $("#user-input").val().trim(); + if (name.length == 0) { + showDanger(".alert-success", ".alert-danger"); + return; + } + var rapName = engine.generate(); + $(".alert-success").text(generateMessage(name, rapName)); + showSuccess(".alert-success", ".alert-danger"); + }); -$(document).ready(function() { + function showSuccess(successSelector, dangerSelector) { + $(dangerSelector).css('display', 'none'); + $(successSelector).css('display', 'block'); + } - var engine = new Generator; - //Add your codez here + function showDanger(successSelector, dangerSelector) { + $(dangerSelector).css('display', 'block'); + $(successSelector).css('display', 'none'); + } + + function generateMessage(name, rapName) { + var escaped = escape(name).split("%20").join(" "); + return escaped + ", your rap name is " + rapName + "!"; + } });