### html tree ```javascript var body = { tagName: 'body', paired: true, subTags: [ { tagName: 'div', paired: true, subTags: [ { tagName: 'span', paired: true, text: 'Enter a data please:' }, { tagName: 'br', paired: false }, { tagName: 'input', paired: false, attr: { type: 'text', id: 'name' } }, { tagName: 'input', paired: false, attr: { type: 'text', id: 'surname' } }, ] }, { tagName: 'div', paired: true, subTags: [ { tagName: 'button', paired: true, text: 'OK', attr: { id: 'ok' } }, { tagName: 'button', paired: true, text: 'Cancel', attr: { id: 'cancel' } } ] } ] } alert('Значения текста во второй кнопке: ' + body.subTags[1].subTags[1].text); alert('Значение атрибута id во втором input: ' + body.subTags[0].subTags[3].attr.id); ``` ### declarative fields ```javascript var notebook = { brand: prompt("Enter a brand"), type: prompt("Enter a type"), model: prompt("Enter a model"), ram: +prompt("Enter a ram"), size: prompt("Enter a size"), weight: +prompt("Enter a weight"), resolution: { width: +prompt("Enter a width"), height: +prompt("Enter a height") } }; var phone = { brand: prompt("Enter a brand"), model: prompt("Enter a model"), ram: +prompt("Enter a ram"), color: prompt("Enter a color") }; var person = { name: prompt("Enter a name"), surname: prompt("Enter a sirname"), married: confirm("Is married?") }; ``` ### object links ```javascript var notebook = { brand: prompt("Enter a brand"), type: prompt("Enter a type"), model: prompt("Enter a model"), ram: +prompt("Enter a ram"), size: prompt("Enter a size"), weight: +prompt("Enter a weight"), resolution: { width: +prompt("Enter a width"), height: +prompt("Enter a height") }, }; var phone = { brand: prompt("Enter a brand"), model: prompt("Enter a model"), ram: +prompt("Enter a ram"), color: prompt("Enter a color"), }; var person = { name: prompt("Enter a name"), surname: prompt("Enter a sirname"), married: confirm("Is married?"), }; person.smartphone = phone; person.laptop = notebook; notebook.owner = person; phone.owner = person; person.smartphone.owner.laptop.owner.smartphone == person.smartphone; ``` ### imperative array fill 3 ```javascript var arr = []; arr[0] = prompt("Введите 1й элемент массива"); arr[1] = prompt("Введите 2й элемент массива"); arr[2] = prompt("Введите 3й элемент массива"); ``` ### while confirm ```javascript var conf; while(!conf){ conf = confirm(); } ``` ### array fill ```javascript var arr = []; while(true){ var arrEl = prompt("Введите новый элемент массива"); if(!arrEl){ break; } arr.push(arrEl); } ``` ### array fill nopush ```javascript var arr = []; while(true){ var arrEl = prompt("Введите новый элемент массива"); if(!arrEl){ break; } arr[arr.length] = arrEl; } ``` ### infinite probability ```javascript var i = 0; while(true){ var rand = Math.random(); i++; if(rand > 0.9){ alert("Число итераций: " + i); break; } } ``` ### empty loop ```javascript while(!prompt("","true")) { } ``` ### progression sum ```javascript var n = +prompt("Введите число N") * 3; var summ = 0; for(i = 1; i < n; i += 3){ summ += i; } alert(summ); ``` ### chess one line ```javascript var str = ""; var isEven = confirm("Длина строки должна быть четной?"); for(i = 0; i < 5; i++) { if(i !== 4 || isEven){ str += " #"; } else{ str += " # " } } alert("'" + str + "'" + " Длина строки: " + str.length); ``` ### numbers ```javascript for(i = 0; i < 10; i++){ for(j = 0; j < 10; j++){ document.write(j); } document.write("
\n") } ``` ### chess ```javascript var chessHeight = 10; var chessWidth = 12; for (var i = 0; i < chessHeight; i++) { if(!(i % 2)){ document.write("."); } for (var j = 0; j < chessWidth - 1; j++) { if(!(j % 2)){ document.write("#"); } else{ document.write("."); } } if(i % 2) { document.write("."); } document.write("
\n"); } ``` ### cubes ```javascript var n = +prompt("Введите длину 'N' массива"); var arr = []; for (var i = 0; i < n; i++) { arr[i] = i * i * i; } alert(arr); ``` ### multiply table ```javascript var arr = []; for (var i = 0; i < 11; i++) { arr[i] = []; for (var j = 0; j < 11; j++) { arr[i][j] = j * i; } } var a = prompt("Введите множимое"); var b = prompt("Введите множитель"); alert(arr[a][b]); ``` ### matrix to html table ```javascript var arr = []; for (var i = 0; i < 11; i++) { arr[i] = []; for (var j = 0; j < 11; j++) { arr[i][j] = j * i; } } var table = "
" + arr[i][j] + " | "; } table += "