// html tree var 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', attrs:{ id: 'ok', }, text: "OK", }, { tagName: 'button', attrs:{ id: 'cancel', }, text: "Cancel", }, ] }, ] } alert(body.subTags[1].subTags[1].text); alert(body["subTags"][1]["subTags"][1]["text"]); alert(body.subTags[0].subTags[3].attrs.id); alert(body["subTags"][0]["subTags"][3]["attrs"]["id"]); // // declarative fields && object links var notebook = { brand: prompt("enter brand"), type: prompt("enter type"), model: prompt("enter model"), ram: prompt("enter ram"), size: prompt("enter size"), weight: prompt("enter weight"), owner: person, resolution: { width: prompt("enter width"), height: prompt("enter height"), }, }; var person = { name: prompt("Enter a name"), surname: prompt("enter a surname"), married: confirm("married?"), smartphone: phone, laptop: notebook, }; var phone = { brand: prompt("enter brand"), model: prompt("enter model"), ram: prompt("enter ram"), color: prompt("enter color"), owner: person, }; // imperative array fill 3 let arr = []; arr[0] = prompt("Введите первый элемент"); arr[1] = prompt("Введите второй элемент"); arr[2] = prompt("Введите третий элемент"); // while confirm let conf1; do { conf1 = confirm("Нажмите ок"); } while (!conf1); let conf2; while (!conf2) { conf2 = confirm("Нажмите ок"); }; // array fill let array = []; for(;;) { let fill = prompt("Введите значение"); if(!fill) { break; } array.push(fill); } alert(array); // array fill nopush let arrOne = []; for (let i = 0; ; i++) { let fill = prompt("Введите значение"); if (!fill) { break; } arrOne[i]= fill; } alert(arrOne); // infinite probability let a; for (a = 0; ; a++) { let num = Math.random(); alert(`Итерация ${a} число ${num}`); if (num > 0.9) { break; } } alert(`Количество итераций ${a + 1}`); // empty loop for(let value = null; value == null; value = prompt("Введите значение")){} // progression sum let num = +prompt("Введите количество элементов арифметической прогрессии"); let sum = 0; for(let i=1; i<= 1+(num-1)*3; i+=3) { sum+=i; } alert(`Сумма равна ${sum}`); // chess one line let t = +prompt("Введите длину строки"); let str = ""; for (let i = 0; i < t ; i++){ if (i % 2 == 0){ str = str + " "; } else{ str = str + "#"; } } alert(str); // numbers let num1 = +prompt("Введите количество строк"); let str1 = ""; for(let i = 0; i < num1; i++){ for(let j = 0; j < 10; j++){ str1 = str1 + j; } str1 = str1 + "\n"; } alert(str1); // chess let h = +prompt("Введите количество строк"); let z = +prompt("Введите количество столбцов"); let chess = ""; for(let i = 0; i < h; i++){ for(let j = 0; j < z; j++){ if((j+i)%2 == 0){ chess = chess + "."; } else{ chess = chess + "#"; } } chess = chess + "\n"; } alert(chess); // cubes let cubes = []; let cub = +prompt("Укажите количество кубов"); for(let i = 0; i < cub; i++){ cubes [i]= i**3; } alert(cubes); // multiply table let table = []; for(let i = 1; i < 11; i++){ table[i] = []; for(let j = 1; j <11; j++){ table[i][j] = i * j; } } let x = +prompt("Введите первый множитель"); let y = +prompt("Введите второй множитель"); alert(`Произведение равно ${table[x][y]}`); // Задание на синий пояс: Треугольник let n = +prompt("Введите длину основания триугольника"); let m = Math.ceil(n/2); let s = ""; let hashCount = 1; let dotCount = m - 1; for(let i = 0; i < m; i++){ s = s + '.'.repeat(dotCount) + '#'.repeat(hashCount) + '.'.repeat(dotCount) + '\n'; hashCount = hashCount + 2; dotCount = dotCount - 1; } alert(s); // matrix to html table document.write (''); document.write (''); document.write (''); let td, content; for (let i = 0; i < 21; i++) { document.write (''); for (let j = 0; j < 21; j++) { if (i == 0 || j == 0) { td = ''); } document.write (''); } document.write ('

Таблица умножения в десятичной системе

'; if (i == j) content = '&#' + '215;'; else if (i == 0) content = '' + j + ''; else if (j == 0) content = '' + i + ''; } else { td = ''; if (i == j) content = '' + i * j + ''; else content = i * j; } document.write (td + content + '
');