|
@@ -0,0 +1,257 @@
|
|
|
+// 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 ('<style>td, caption {font-family: arial}</style>');
|
|
|
+document.write ('<table align="center" bgcolor="fdfdfd" ');
|
|
|
+document.write ('cellspacing="0" cellpadding="4" ');
|
|
|
+document.write ('border="1" style="border-collapse: collapse">');
|
|
|
+document.write ('<caption><p><b>Таблица умножения в десятичной системе</caption></b>');
|
|
|
+
|
|
|
+let td, content;
|
|
|
+for (let i = 0; i < 21; i++)
|
|
|
+ {
|
|
|
+ document.write ('<tr>');
|
|
|
+ for (let j = 0; j < 21; j++)
|
|
|
+ {
|
|
|
+ if (i == 0 || j == 0)
|
|
|
+ {
|
|
|
+ td = '<td align="right" width="4%" bgcolor="efefef">';
|
|
|
+ if (i == j) content = '<b>&#' + '215;</b>';
|
|
|
+ else if (i == 0) content = '<b>' + j + '</b>';
|
|
|
+ else if (j == 0) content = '<b>' + i + '</b>';
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ td = '<td align="right">';
|
|
|
+ if (i == j) content = '<b>' + i * j + '</b>';
|
|
|
+ else content = i * j;
|
|
|
+ }
|
|
|
+ document.write (td + content + '</td>');
|
|
|
+ }
|
|
|
+ document.write ('</tr>');
|
|
|
+ }
|
|
|
+
|
|
|
+document.write ('<table>');
|