Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const form = document.getElementById('nameForm');
+ const nameCard = document.getElementById('nameCard');
+ const firstNameElement = document.getElementById('firstName');
+ const middleNameElement = document.getElementById('middleName');
+ const userLastNameElement = document.getElementById('userLastName');
+ const regenerateBtn = document.getElementById('regenerateBtn');
+
+ const firstNames = [
+ 'Emma', 'Liam', 'Olivia', 'Noah', 'Ava', 'Ethan', 'Sophia', 'Mason',
+ 'Isabella', 'William', 'Mia', 'James', 'Charlotte', 'Alexander', 'Amelia'
+ ];
+
+ const middleNames = [
+ 'Grace', 'James', 'Rose', 'Alexander', 'Marie', 'William', 'Elizabeth',
+ 'Joseph', 'Anne', 'Michael', 'Jane', 'Thomas', 'Catherine', 'Robert'
+ ];
+
+ function generateName(lastName) {
+ const firstName = firstNames[Math.floor(Math.random() * firstNames.length)];
+ const middleName = middleNames[Math.floor(Math.random() * middleNames.length)];
+
+ return {
+ firstName,
+ middleName,
+ lastName
+ };
+ }
+
+ function displayName(nameObj) {
+ firstNameElement.textContent = nameObj.firstName;
+ middleNameElement.textContent = nameObj.middleName;
+ userLastNameElement.textContent = nameObj.lastName;
+ nameCard.classList.remove('hidden');
+ regenerateBtn.classList.remove('hidden');
+ }
+
+ form.addEventListener('submit', (e) => {
+ e.preventDefault();
+ const lastName = document.getElementById('lastName').value.trim();
+
+ if (lastName) {
+ const generatedName = generateName(lastName);
+ displayName(generatedName);
+ }
+ });
+
+ regenerateBtn.addEventListener('click', () => {
+ const lastName = document.getElementById('lastName').value.trim();
+ const generatedName = generateName(lastName);
+ displayName(generatedName);
+ });
+ });