Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const form = document.getElementById('nameForm');
+ const results = document.getElementById('results');
+ const namesGrid = document.getElementById('namesGrid');
+ const generateMoreBtn = document.getElementById('generateMore');
+
+ // Name databases
+ const boyNames = ['Alexander', 'Benjamin', 'Christopher', 'Daniel', 'Ethan', 'Felix', 'Gabriel', 'Henry'];
+ const boyMiddle = ['James', 'William', 'Joseph', 'Michael', 'Robert', 'David', 'John', 'Thomas'];
+ const girlNames = ['Sophia', 'Olivia', 'Emma', 'Charlotte', 'Amelia', 'Isabella', 'Mia', 'Luna'];
+ const girlMiddle = ['Rose', 'Grace', 'Elizabeth', 'Marie', 'Jane', 'Anne', 'Claire', 'Faith'];
+ const neutralNames = ['Avery', 'Jordan', 'Riley', 'Morgan', 'Quinn', 'Taylor', 'Sam', 'Alex'];
+ const neutralMiddle = ['Sky', 'River', 'Rain', 'Sage', 'Winter', 'Blue', 'Bay', 'Blair'];
+
+ function generateNames(lastName, gender, count = 4) {
+ let firstNames, middleNames;
+
+ switch(gender) {
+ case 'boy':
+ firstNames = boyNames;
+ middleNames = boyMiddle;
+ break;
+ case 'girl':
+ firstNames = girlNames;
+ middleNames = girlMiddle;
+ break;
+ case 'neutral':
+ firstNames = neutralNames;
+ middleNames = neutralMiddle;
+ break;
+ }
+
+ const names = [];
+ for(let i = 0; i < count; i++) {
+ const firstName = firstNames[Math.floor(Math.random() * firstNames.length)];
+ const middleName = middleNames[Math.floor(Math.random() * middleNames.length)];
+ names.push({ first: firstName, middle: middleName });
+ }
+ return names;
+ }
+
+ function displayNames(names, lastName) {
+ namesGrid.innerHTML = '';
+ names.forEach(name => {
+ const nameCard = document.createElement('div');
+ nameCard.className = 'name-card';
+ nameCard.innerHTML = `
+ ${name.first} ${name.middle} ${lastName}
+ `;
+ namesGrid.appendChild(nameCard);
+ });
+ results.classList.remove('hidden');
+ }
+
+ form.addEventListener('submit', (e) => {
+ e.preventDefault();
+ const lastName = document.getElementById('lastName').value.trim();
+ const gender = document.querySelector('input[name="gender"]:checked').value;
+
+ const names = generateNames(lastName, gender);
+ displayNames(names, lastName);
+ });
+
+ generateMoreBtn.addEventListener('click', () => {
+ const lastName = document.getElementById('lastName').value.trim();
+ const gender = document.querySelector('input[name="gender"]:checked').value;
+
+ const names = generateNames(lastName, gender);
+ displayNames(names, lastName);
+ });
+ });