Generic Name Generator

by Dan Shahin

HTML

<h2>Generic Name Generator</h2>
<input type="text" class="first" placeholder="first" value="daniel"/>
<input type="text" class="middle" placeholder="middle" value="john"/>
<input type="text" class="last" placeholder="last" value="shahin"/>
<button class="header">show/hide data</button>


    
    <div class="inputs">
        <label for="label">label</label>
        <input type="text" class="label" id="label" value="Code" placeholder="label"/><br/>
        <label for="adjectives">adjectives</label>
        <textarea name="adjectives" id="adjectives" cols="30" rows="10" class="adjectives">
adaptable
adventurous
affable
affectionate
agreeable
ambitious
amiable
amicable
amusing
brave
bright
broad-minded
calm
careful
charming
communicative
compassionate 
conscientious
considerate
convivial
courageous
courteous
creative
decisive
determined
diligent
diplomatic
discreet
dynamic
easygoing
emotional
energetic
enthusiastic
exuberant
fair-minded
faithful
fearless
forceful
frank
friendly
funny
generous
gentle
good
gregarious
hard-working
helpful
honest
humorous
imaginative
impartial
independent
intellectual
intelligent
intuitive
inventive
kind
loving
loyal
modest
neat
nice
optimistic
passionate
patient
persistent 
pioneering
philosophical
placid
plucky
polite
powerful
practical
pro-active
quick-witted
quiet
rational
reliable
reserved
resourceful
romantic
self-confident
self-disciplined
sensible
sensitive
shy
sincere
sociable
straightforward
sympathetic
thoughtful
tidy
tough
unassuming
understanding
versatile
warmhearted
willing
witty</textarea>
<label for="nouns">nouns</label>
<textarea name="nouns" id="nouns" cols="30" rows="10" class="nouns">
Army
Audience
Band
Bevy
Bouquet
Brood
Bunch
Cabinet 
Caravan
Cartload
Choir
Clan
Colony
Congregation 
Corps
Drove
Family
Flock
Flutter
Gaggle
Galaxy
Gang
Group
Herd
Jury
Library
Mob 
Nest
Pack
Panel
Quiver
Range
Regiment
School 
Shoal  
Squadron
Swarm
Team 
Village
Yoke</textarea>
        
    </div>


<h2 class="legend">your name...

CSS

.header {background-color:white;}
.inputs{display: none;}
label {display:block;}

JavaScript

var letters = 'abcdefghijklmnopqrstuvwxyz'.split(''),
    lookup = {};
for (var i = 0; i < letters.length; i++) {
    lookup[letters[i]] = i;
}
console.log('here');
$('input,textarea').keyup(function () {
    var nouns = $('.nouns').val().split(/\n/),
        adjectives = $('.adjectives').val().split(/\n/),
        label = $('input.label').val(),
        first = $('.first').val(),
        last = $('.last').val(),
        middle = $('.middle').val(),
        salt = lookup[middle.charAt(0).toLowerCase()] * middle.length,
        nounNum = ((first.length + lookup[middle.charAt(0).toLowerCase()])* last.length + middle.length + salt) * last.length,
        nounIndex = nounNum % nouns.length,
        noun = nouns[nounIndex],
        adjectiveNum = (first.length  )* ((last.length + lookup[middle.charAt(0).toLowerCase()]) * first.length + salt),
        adjectivesIndex = adjectiveNum % adjectives.length,
        adjective = adjectives[adjectivesIndex];
    $('.legend').html(first + ' ' + middle + ' ' + last );
    $('.output').html(adjective.capitalize() + ' ' + noun.capitalize());
    $('span.label').html(label +' name is:');
});

String.prototype.capitalize = function () {
    return this.charAt(0).toUpperCase() + this.slice(1);
};

$('.header').click(function(){
   $('.inputs').toggle('slow'); 
});

$('.first').keyup();