<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
</head>
<body>
	<div id="container"></div>
	<script>
//----------3 persons --- different fields --- fields check
			/*let a={
				name:'John',
				surname:'Johnson'
			};

			let b={
				name:"Ivan",
				surname:"Ivanov"
			};

			let c={
				name:'Kevin',
				surname:"McKalister"
			};

			a.sex='man';
			a.age=17;
			b.fathername='Jonson';
			c.age=19;

			let key =prompt('','');

			if(key in a){
				alert(a[key]);
			}*/

//----------array of persons 
/*			let a={
				name:'John',
				surname:'Johnson'
			};

			let b={
				name:"Ivan",
				surname:"Ivanov"
			};

			let c={
				name:'Kevin',
				surname:"McKalister"
			};

			let persons=[a,b,c];

			persons.push({name:"Frank", surname:'Lampard'});
			
	//loop of persons
			for(let item of persons){
				console.log(item);
			}

	//loop of name and surname
			for(let item of persons){
				console.log(item.name+" "+item.surname);
			}


	//loop of loop of values
			for(let item of persons){
				for(let name of Object.values(item)){
					console.log(name);
				}
			}

	//fullName
			for(let item of persons){
				item.fullName=item.name+" "+item.surname;
				console.log(item.fullName);
			}
			console.log(persons);

	//serialize
			let json=JSON.stringify(persons,null,2);
			console.log(json);

	//deserialize
			let d=JSON.parse(json)[0];
			console.log(d);
			persons.push(d);
			console.log(persons);*/
			
//----------HTML
			/*let str = "<table border='1'><tr><td>Имя</td><td>Фамилия</td></tr>";
			for (let i=0;i<persons.length;i++){

				let g=persons[i];
    			str += `<tr><td>${g.name}</td><td>${g.surname}</td></tr>`;
			}
			str += "</table>";
			document.write(str);*/

//----------HTML optional fields --- HTML tr color
			/*
			let str = "<table border='1'>";
			for (let i=0;i<persons.length;i++){
				
				let g=persons[i];
				if(i%2){
					str+="<tr bgcolor='yellow'>";
				}else{
					str+='<tr>';
				}
				for(let item in g){
					if(item){
						str+=`<td>${item}: ${g[item]}</td>`;
					}
				}
				str+='</tr>';
			}
			str += "</table>";
			document.write(str);*/

//---------HTML th optional
			/*persons[2].age=19;
			persons[3].age=27;
			persons[3].sex='man';
			let keys=[];
			for(let item of persons){
				for(let i of Object.keys(item)){
					if(!keys.includes(i)){
						keys.push(i);
					}
				}
			}
			console.log(keys);
			let str = "<table border='1'><tr>";
			for(let i of keys){
				str+=`<th>${i}</th>`;
			}
			str+='</tr>';

			for(let item of persons){
				str+='<tr>';
				for(let it in item){
					for(let i=0;i<keys.length;i++){
						if(keys[i]==it){
							str+=`<td bgcolor='yellow'>${item[it]}</td>`;
						}	
					}
				}
				str+='</tr>';
			}
			document.write(str);*/

//----------Blue belt

	//появляется ячейка table -> {tbody}? -> tr -> td
			var someTree = {
    		tagName: "table", 
    		subTags: [ 
        		{
                    tagName: "tr",
                    subTags: [
                        {
                           	tagName: "td",
                            text: "some text",
                        },
                        {
                            tagName: "td",
                            text: "some text 2",
                        }
                    ]
        		}
    		],
    		attrs: {
        		border: 1,
    		},
		}

		let str='';
		for(let item in someTree){
			if(item=='tagName'){
				let [key] = Object.keys(someTree['attrs']);
				let [value]= Object.values(someTree['attrs']);
				str+=`<${someTree['tagName']} ${key}=${value}>`;
			}
			
			if(item=='subTags'){
				for(let item2 of someTree[item]){
					for(let item3 in item2){
						// str+=`<${item2['tagName']}>`;
						if(item3=='subTags'){
							for(let item4 of item2['subTags']){
								console.log(item4);
							  for(let item5 in item4){
								if(item5=='tagName'){
									str+=`<${item4['tagName']}>${item4['text']}</${item4['tagName']}>`;	
								}	
							  }
						    }
						}
					}
				}
			}
			
		}

		document.write(str);

//------destruct array
		//четные числав переменные even1, even2
		/*let arr=[1,2,3,4,5,'a','b','c'];
		for(let i=0; i<arr.length; i++) {
 			for(let j=0; j<arr.length; j++ ){
 				if(arr[j]%2 === 1){
 					arr.splice(j,1)
      				break;
    			}
 			}	
  		};
		let [even1,even2]=arr;
		console.log(arr);
		console.log(even1+" : "+even2);	*/

		//нечетные в odd1, odd2, odd3
		/*let arr2=[1,2,3,4,5,'a','b','c'];
		let [odd1,odd2,odd3]=arr2.filter(x=>x%2);
		console.log(odd1+" : "+odd2+' : '+odd3);*/

		//буквы в отдельный массив
		/*let arr3=arr2.filter(function(x){
			if(!Number(x)){
				return x;
			}
		});
		console.log(arr3);*/

//------destruct string
		//число в переменную number
		/*let arr=[1,'abc'];	
		let [number]=arr;
		console.log(number);*/

		//букву а в переменную s1
		//букву b в переменную s2
		//букву с в переменную s3 
		/*let [s1,s2,s3]=[...arr[1]];
		console.log(s1+" : "+s2+" : "+s3);*/	

//------destruct 2
		/*let obj = {
			name: 'Ivan',
           	surname: 'Petrov',
           	children: [
           		{
           			name: 'Maria'
           		}, 
           		{
           			name: 'Nikolay'
           		}
           	]
        };

        let {children:[{name:name1},{name:name2}]}=obj;
        console.log(name1 + " : "+name2);*/

//------destruct 3
		let arr = [1,2,3,4,5,6,7,10];
		let [a,b]=arr;

		console.log(a+' : '+b+' : '+length);

		//вопрос:как дуструктуризовать length
					
//------Black belt
		//in process
						
						
				


			

			






	</script>

</body>
</html>