serg155alternate 2 роки тому
батько
коміт
4e026f663b
1 змінених файлів з 22 додано та 15 видалено
  1. 22 15
      HW8 Functioms 2/script.js

+ 22 - 15
HW8 Functioms 2/script.js

@@ -181,19 +181,26 @@ let someTree = {
     },
 }
 
-function htmlRecConstructor (obj) {
-    let {tagName, children, attrs, text} = obj;
-    let  body = `<${tagName} ${Object.keys(attrs)} = ${Object.values(attrs)}>`; 
-  /*   for (let key in obj) { 
-        body += `<${tagName}>`; 
-        console.log(typeof children);
-        if (typeof children == 'object') { 
-            // htmlRecConstructor(obj)                      
-        } 
-        
-    } */
-    body +=`</${tagName}>` 
-    document.write(body);      
-  //console.log(body);   
+function htmlRecConstructor (obj) {   
+    
+         let {tagName, children, attrs, text} = obj;
+         let body =`<${tagName}>`; 
+        if (typeof children ==="object"){
+          for (let tag of children){
+             console.log(tag); 
+             let  {tagName, children, attrs, text} = tag;
+             body +=`<${tagName}>`; 
+             
+             htmlRecConstructor(tag); 
+         body +=`<${tagName}>`;     
+         } 
+        }  else body +=`<${tagName}>`;  
+          body.innerText +=`<${text}>`; 
+       
+         
+console.log(body);  
+   document.write(body); 
+  
 };  
-htmlRecConstructor(someTree) ;
+htmlRecConstructor(someTree);  
+//document.write(htmlRecConstructor(someTree));