Changed around line 1
+ document.getElementById('generate-btn').addEventListener('click', generateFamilyTree);
+
+ function generateFamilyTree() {
+ const container = document.getElementById('tree-container');
+ container.innerHTML = '';
+ const memberCount = Math.floor(Math.random() * 5) + 6;
+ const tree = createTree(memberCount);
+ renderTree(tree, container);
+ }
+
+ function createTree(memberCount) {
+ const members = [];
+ for (let i = 0; i < memberCount; i++) {
+ members.push({
+ name: `Member ${i + 1}`,
+ children: []
+ });
+ }
+ for (let i = 1; i < memberCount; i++) {
+ const parentIndex = Math.floor(Math.random() * i);
+ members[parentIndex].children.push(members[i]);
+ }
+ return members[0];
+ }
+
+ function renderTree(node, container) {
+ const nodeElement = document.createElement('div');
+ nodeElement.className = 'node';
+ nodeElement.textContent = node.name;
+ container.appendChild(nodeElement);
+
+ if (node.children.length > 0) {
+ const childrenContainer = document.createElement('div');
+ childrenContainer.className = 'children';
+ node.children.forEach(child => renderTree(child, childrenContainer));
+ container.appendChild(childrenContainer);
+ }
+ }