//html tree let body = { name: 'body', children: [ { name: 'div', children: [ { name: 'span', children: 'Enter a data please', }, { name: 'br', }, { name: 'input', atrrs: { type: 'text', id: 'name', }, }, { name: 'input', atrrs: { type: 'text', id: 'name', }, }, ] }, { name: 'div', children: [ { name: 'button', atrrs: { id: 'ok', children: 'OK', } }, { name: 'button', atrrs: { id: 'cancel', children: 'Cancel', } }, ], } ], }; alert("Значение текста во второй кнопке - " + body.children[1].children[1].atrrs.children); alert("Значение атрибута id во втором input - " + body.children[0].children[3].atrrs.id); //declarative fields let laptop = { brand: prompt("Введите название бренда ноутбука:") || "HP", type: prompt("Введите тип:") || "440 G4", model: prompt("Введите модель:") || "Y7Z75EA", ram: +prompt("Введите количество оперативки:") || 4, size: prompt("Введите размер:") || "14", weight: +prompt("Введите вес:") || 1.8, resolution: { width: +prompt("Введите разрешение экрана (ширина):") || 1920, height: +prompt("Введите разрешение экрана (высота):") || 1080, }, }; let smartphone = { brand: prompt("Введите название бренда телефона:") || "meizu", model: prompt("Введите модель:") || "m2", ram: +prompt("Введите количество оперативки:") || 2, color: prompt("Введите цвет:") || "black", }; let person = { name: prompt("Введите имя:") || "Donald", surname: prompt("Введите фамилию:") || "Trump", married: confirm("Вы в браке?") || true, } //object links person["smartphone"] = smartphone; person["laptop"] = laptop; smartphone["owner"] = person; laptop["owner"] = person; alert(person.smartphone.owner.laptop.owner.smartphone == person.smartphone); //true //imperative array fill 3 let emptyArray = []; emptyArray[0] = +prompt("Введите первое число"); emptyArray[1] = +prompt("Введите второе число"); emptyArray[2] = +prompt("Введите третье число"); //while confirm let joke; while (joke !== true) { joke = confirm("Оп"); } //array fill let arrayFill = []; let elementFill; while (elementFill !== null) { elementFill = prompt("Введите что-нибудь)"); if (elementFill === null) { break; } someArray.push(elementFill); } //array fill nopush let arrayNoPush = []; for (let i = 0, j; j !== null; i++) { j = prompt("Введите что-нибудь)") if (j === null) { break; } arrayNoPush[i] = j; } //infinite probability let someArray = []; for (let i = 0; i < Infinity; i++) { let randomNumber = Math.random(); console.log(i); if (randomNumber > 0.9) { alert("Количество итераций: " + someArray.length); break; } someArray[i] = randomNumber; } //empty loop let someQuestion; do { someQuestion = prompt('???'); } while (someQuestion != "") //while(prompt()===null) ; //progression sum let amountIteration = +prompt("Введите N: "); let sum = 0; for (let i = 1, j = 1; i <= amountIteration; i++, j += 3) { sum += j; } alert("Сумма арифметической прогрессии: " + sum); //chess one line let str = ""; let strElement; for (let i = 0; i <= 10; i++) { if ((i % 2) === 0) { strElement = " "; } else { strElement = "#"; } str += strElement; } alert(str); //numbers let strOut = ""; for (let i = 0; i < 10; i++) { for (let j = 0; j < 10; j++) { strOut += String(j); } strOut += "\n"; } alert(strOut); //chess let chessWidth = prompt("Размер доски (ширина)"); let chessHeight = prompt("Размер доски (высота)"); let chess = ""; let chessElement; for (let i = 0; i < chessHeight; i++) { for (let j = 0; j < chessWidth; j++) { if ((j % 2) === 0) { chessElement = "."; } else { chessElement = "#"; } chess += chessElement; } if ((i % 2) === 1) { chess = chess.replace(/[.#]/g, c => c == '.' ? '#' : '.'); } else { chess = chess.replace(/[.#]/g, c => c == '#' ? '.' : '#'); } chess += "\n"; } alert(chess); //cubes let amountIndex = +prompt("Введите N: "); let arrayOfIndex = []; for (let i = 0; i < amountIndex; i++) { arrayOfIndex[i] = Math.pow(i, 3); } alert("Ваш массив: " + arrayOfIndex); //multiply table let multiplyArray = []; for (let i = 0; i <= 10; i++) { multiplyArray[i] = []; for (let j = 0; j <= 10; j++) { multiplyArray[i][j] = i * j; } } let firstNumber = +prompt("Введите первое число (1-10)"); let secondNumber = +prompt("Введите второе число (1-10)"); alert("Результат умножения: " + multiplyArray[firstNumber][secondNumber]); //matrix to html table let strToHtml = "" for (let i = 1; i <= 10; i++) { strToHtml += `` for (let j = 1; j <= 10; j++) { strToHtml += `` } strToHtml += `` } strToHtml += "
${multiplyArray[i][j]}
" document.write(strToHtml) //Задание на синий пояс: Треугольник let strTriangle = ""; for (let i = 0; i < 6; i++) { for (let j = 0; j < 5 - i; j++) { strTriangle += "."; } for (let k = 0; k < i * 2 + 1; k++) { strTriangle += "#"; } for (let j = 0; j < 5 - i; j++) { strTriangle += "."; } strTriangle += "\n" } alert(strTriangle);