Changed around line 1
+ const familyNameInput = document.getElementById('familyName');
+ const firstNameInput = document.getElementById('firstName');
+ const generateButton = document.getElementById('generateTree');
+ const familyTreeContainer = document.getElementById('familyTree');
+
+ const chineseFirstNames = ['Wei', 'Jing', 'Ming', 'Li', 'Xiu', 'Hua', 'Yong', 'Qiang', 'Mei', 'Lan'];
+ const jobs = ['Carpenter', 'Hostess', 'Butcher', 'Painter'];
+ const relationships = ['Grandmother', 'Grandfather', 'Sister', 'Brother', 'Uncle'];
+
+ function getRandomElement(array) {
+ return array[Math.floor(Math.random() * array.length)];
+ }
+
+ function generateRandomAge(relationship) {
+ if (relationship === 'Grandmother' || relationship === 'Grandfather') {
+ return Math.floor(Math.random() * 30) + 60;
+ } else if (relationship === 'Uncle') {
+ return Math.floor(Math.random() * 20) + 40;
+ } else {
+ return Math.floor(Math.random() * 15) + 20;
+ }
+ }
+
+ function generateFamilyMember(familyName) {
+ const firstName = getRandomElement(chineseFirstNames);
+ const relationship = getRandomElement(relationships);
+ const job = getRandomElement(jobs);
+ const age = generateRandomAge(relationship);
+
+ return {
+ name: `${firstName} ${familyName}`,
+ relationship,
+ job,
+ age
+ };
+ }
+
+ function displayFamilyTree(familyName, firstName) {
+ familyTreeContainer.innerHTML = '';
+
+ // Add yourself
+ const yourself = document.createElement('div');
+ yourself.className = 'family-member';
+ yourself.innerHTML = `
+
${firstName} ${familyName}
+ `;
+ familyTreeContainer.appendChild(yourself);
+
+ // Generate 5 family members
+ for (let i = 0; i < 5; i++) {
+ const member = generateFamilyMember(familyName);
+ const memberDiv = document.createElement('div');
+ memberDiv.className = 'family-member';
+ memberDiv.innerHTML = `
+
${member.name}
+ `;
+ familyTreeContainer.appendChild(memberDiv);
+ }
+ }
+
+ generateButton.addEventListener('click', () => {
+ const familyName = familyNameInput.value.trim();
+ const firstName = firstNameInput.value.trim();
+
+ if (familyName && firstName) {
+ displayFamilyTree(familyName, firstName);
+ } else {
+ alert('Please enter both your family name and first name.');
+ }
+ });