// Task1 3 persons // // const a = { // name: "Lena", // surname: "Ivanova", // } // // const b = { // name: "Kate", // surname: "Smit", // } // // const c = { // name: "Bob", // surname: "Petrov", // } // // // Task2 different fields // // a.age = 18; // a.fathername = "Makalester"; // // b.sex = "femel"; // b.age = "25"; // // c.fathername = "Ivanovich" // c.sex = "mele"; // Task3 Fields check // if(typeof a.age){ // alert(a.age) // } // function check(obj, prop){ // if(prop in obj){ // alert(obj[prop]); // } // } // check(c, "sex"); // Task4 array of persons // // const persons = [a, b, c, {name: "Pavel", surname: "Pavlov",}]; // // // Task5 loop of persons // // for (let i = 0; i < persons.length; i++) { // console.log(persons[i]); // } // // // Task6 loop of name and surname // // for (let i = 0; i < persons.length; i++) { // console.log(persons[i].name, persons[i].surname); // } // Task7 loop of loop of value // for (let i=0; i${persons[i].name}${persons[i].surname}` // } // str += "" // // document.write(str) // Task12 HTML optional fields // + // Task 13 // + // Task 14 // const json = `{"persons" : [ // {"name": "Lena", "surname": "Ivanova", "age": "18", "fathername": "Makalester", "fullName": "Lena Ivanova Makalester"}, // {"name": "Kat", "surname": "Smit", "sex": "femel", "age": "25", "fullName": "Kate Smit"}, // {"name": "Bob", "surname": "Petrov", "fathername": "Ivanovich", "sex": "mele", "fullName": "Bob Petrov Ivanovich"}, // {"name": "Pavel", "surname": "Pavlov", "fullName": "Pavel Pavlov "} // ]}`; // const persons = JSON.parse(json).persons; // const headCaption = { // name: 'Name', // surname: 'Surname', // fathername: 'Fathername', // fullName: 'Full name', // age: 'Age', // sex: 'Sex', // } // // // // let str1 = ""; // str1 +=``; // // for (let key in headCaption){ // str1+=`` // } // str1 +=``; // str1 +=``; // // for (let i = 0; i < persons.length; i++) { // str1 += ``; // for (let caption in headCaption){ // str1+=`` // } // // str1 += ``; // } // str1 +=``; // str1 += `
${headCaption[key]}
// ${persons[i][caption] ? persons[i][caption] : "-"} //
`; // // document.write(str1); // Blue belt task const someTree = { tagName: "table", //html tag subTags: [ //вложенные тэги { tagName: "tr", subTags: [ { tagName: "td", text: "some text", }, { tagName: "td", text: "some text 2", }, ] } ], attrs: { border: 1, }, }; console.log(Object.keys(someTree.attrs)[0]) function createHtml(objTree) { let domStructure = ''; domStructure += `<${objTree.tagName} ${Object.keys(objTree.attrs)[0]} : ${Object.values(objTree.attrs)[0]}>`; for (let i = 0; i < objTree.subTags.length; i++) { domStructure += `<${objTree.subTags[i].tagName}>` for (let j = 0; j < objTree.subTags[i].subTags.length; j++) { domStructure += `<${objTree.subTags[i].subTags[j].tagName}>`; domStructure += objTree.subTags[i].subTags[j].text; domStructure += ``; } domStructure += `` } domStructure += `` document.write(domStructure); } createHtml(someTree); // Task blue belt destruct array let arr = [1, 2, 3, 4, 5, "a", "b", "c"]; const [odd1, even1, odd2, even2, odd3, ...rest] = arr; //Task blue belt destruct string let arr1 = [1, "abc"]; const [number, [s1,s2,s3]] = arr1; console.log(number , s3); // Task blue belt destruct2 const obj = {name: 'Ivan', surname: 'Petrov', children: [{name: 'Maria'}, {name: 'Nikolay'}]} const {children: [{name: name1}, {name: name2}]}=obj; console.log(name1); console.log(name2); // Task blue belt destruct3 let arr2 = [1,2,3,4, 5,6,7,10]; const [a,b, ...c] = arr2; const [ , , length] =[ a,b, c.length] console.log( a, b, length);