diff --git a/js/script.coffee b/js/script.coffee new file mode 100644 index 0000000..941d905 --- /dev/null +++ b/js/script.coffee @@ -0,0 +1,45 @@ +class Generator + constructor: -> + @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' + ] + @first_names = [ + 'Inspectah', 'Masta', 'Poppa', + 'Five Foot', 'Ghostface', 'Old Dirty' + ] + @transforms = [ + ((s) -> s.toUpperCase()[0]), + ((s) -> s.toUpperCase().split('').join('.') + '.'), + ((s) -> s.replace /s|S/g, '$$$$'), + ((s) -> s) + ] + + get_name: (submitted_name) -> + structures = [ + @first_names.random() + ' {}', + @first_names.random() + ' {} ' + @last_names.random(), + '{} ' + @last_names.random() + ] + + name = @transforms.random() submitted_name + structures.random().replace '{}', name + +Array.prototype.random = -> @[Math.floor(Math.random() * @.length)] + +engine = new Generator + +$('.response, .error').hide() +$('#enter').click -> + $('.response, .error').hide() + input = $('#user-input').val() + if input.length > 0 + name = engine.get_name input + $('.response').text name + $('.response').show() + else + $('.error').show() + true diff --git a/js/script.js b/js/script.js index 2f2cff7..bf84590 100644 --- a/js/script.js +++ b/js/script.js @@ -1,32 +1,55 @@ - - -/** - * 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']; - -} - - -//Add your codez here - - -$(document).ready(function() { - - var engine = new Generator; - //Add your codez here - -}); +// Generated by CoffeeScript 1.12.6 +(function() { + var Generator, engine; + + Generator = (function() { + function Generator() { + 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.transforms = [ + (function(s) { + return s.toUpperCase()[0]; + }), (function(s) { + return s.toUpperCase().split('').join('.') + '.'; + }), (function(s) { + return s.replace(/s|S/g, '$$$$'); + }), (function(s) { + return s; + }) + ]; + } + + Generator.prototype.get_name = function(submitted_name) { + var name, structures; + structures = [this.first_names.random() + ' {}', this.first_names.random() + ' {} ' + this.last_names.random(), '{} ' + this.last_names.random()]; + name = this.transforms.random()(submitted_name); + return structures.random().replace('{}', name); + }; + + return Generator; + + })(); + + Array.prototype.random = function() { + return this[Math.floor(Math.random() * this.length)]; + }; + + engine = new Generator; + + $('.response, .error').hide(); + + $('#enter').click(function() { + var input, name; + $('.response, .error').hide(); + input = $('#user-input').val(); + if (input.length > 0) { + name = engine.get_name(input); + $('.response').text(name); + $('.response').show(); + } else { + $('.error').show(); + } + return true; + }); + +}).call(this);