// html tree { let body = { tagName: "body", subTags: [ { tagName: "div", subTags: [ { tagName: "span", text: "Enter a data please:", }, { tagName: "br", }, { tagName: "input", attrs: { type: "text", id: "name", }, }, { tagName: "input", attrs: { type: "text", id: "surname", }, }, ], }, { tagName: "div", subTags: [ { tagName: "button", text: "OK", attrs: { id: "ok", }, }, { tagName: "button", text: "Cancel", attrs: { id: "cancel", }, }, ], }, ], }; console.log(body.subTags[1].subTags[1].text); console.log(body.subTags[0].subTags[3].attrs.id); // declarative fields and object links { var notebook = { brand: prompt("Введите марку ноутбука"), type: prompt("Введите тип"), model: prompt("Введите модель ноутбука"), ram: +prompt("Введите количесство оперативки"), size: +prompt("Введите диагональ экрана"), weight: +prompt("Вес ноутбука"), resolution: { width: +prompt("Ширина экрана ноутбука"), height: +prompt("Высота экрана ноутбука"), }, owner: person, }; var phone = { brand: prompt("Введите марку телефона"), model: prompt("Введите модель телефона"), ram: +prompt("Введите количество оперативки"), color: prompt("Введите цвет телефона"), owner: person, }; var person = { name: prompt("Введите имя"), surname: prompt("Введите фамилию"), married: confirm("женат"), smartphone: phone, laptop: notebook, } } // imperative array fill 3 { let arr = []; arr[0] = prompt('Введите первый элемент массива'), arr[1] = prompt('Введите второй элемент массива'), arr[2] = prompt('Введите третий элемент массива'); } // while confirm let cycle = confirm(); while (cycle == false) { cycle = confirm(); } // array fill { let arr = []; let arrPush = [] while (arr) { arrPush.push(arr = prompt()) if (arr === null) { break; } } } // array fill nopush { let arrNoPush = [] for (let i = 0; i != null; i++) { arrNoPush[i] = prompt("Введите для примера что-то!"); if (arrNoPush[i] === null) break; } } // infinite probability { let number = 0; while (true) { let randomNumber = Math.random(); number++; if (randomNumber > 0.9) { alert("количество итераций " + number); alert("Случайное число " + randomNumber); break; } } } // empty loop // progression sum for (let i = 0; i < 10000; i++) { console.log(i); } // chess one line { let i = '#'; let str = " "; for (j = 0; j < 5; j++) { str += i + " "; } console.log(str); } // numbers { let numbers = ""; for (let i = 0; i <= 9; i++) { for (let a = 0; a <= 9; a++) { numbers += a; } numbers += "\n"; } console.log(numbers); } // chess { let boardChess = ""; for (let i = 0; i < 10; i++) { for (let a = 0; a < 12; a++) { boardChess += (a % 2) == (i % 2) ? "." : "#"; } boardChess += "\n"; } console.log(boardChess); } // cubes for (let indexСubes = []; ;) { let index = indexСubes.length; let expon = index ** 3; indexСubes.push(expon); if (indexСubes.length == 20) { console.log(indexСubes); break; } } // multiply table let arr = Array(10); for (let i = 1; i < 10; i++) { arr[i] = [...Array(10)].map((_, j) => i * j); } console.log(arr[5][6]); console.log(arr[7][2]); // Задание на синий пояс: Треугольник,нужно еще пофиксить let i = 0, j = 0; let point = "", lattice = ""; while (i <= 5) { point = ""; lattice = ""; for (j = 0; j < 5 - i; j++) point += "."; for (j = 0; j < 2 * i + 1; j++) lattice += "#"; console.log(point + lattice + point); i++; } }