|
@@ -1,299 +1,312 @@
|
|
|
/* html tree */
|
|
|
|
|
|
- let body = {
|
|
|
- tagName : 'body',
|
|
|
- subTags : [
|
|
|
- {
|
|
|
- tagName : 'div',
|
|
|
- subTags: [
|
|
|
- {
|
|
|
- tagName : 'span',
|
|
|
- text : 'Enter a data please',
|
|
|
- tagName : 'br',
|
|
|
+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 : 'name'
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- tagName : 'input',
|
|
|
- attrs : {
|
|
|
- type : 'text',
|
|
|
- id : 'surname'
|
|
|
- }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: 'input',
|
|
|
+ attrs: {
|
|
|
+ type: 'text',
|
|
|
+ id: 'surname'
|
|
|
}
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- tagName : 'div',
|
|
|
- subTags : [
|
|
|
- {
|
|
|
- tagName : 'button',
|
|
|
- attrs : {
|
|
|
- id : 'ok'
|
|
|
- },
|
|
|
- text : 'OK'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: 'div',
|
|
|
+ subTags: [
|
|
|
+ {
|
|
|
+ tagName: 'button',
|
|
|
+ attrs: {
|
|
|
+ id: 'ok'
|
|
|
},
|
|
|
- {
|
|
|
- tagName : 'button',
|
|
|
- attrs : {
|
|
|
- id : 'cancel'
|
|
|
- },
|
|
|
- text : 'Cancel'
|
|
|
+ text: 'OK'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: 'button',
|
|
|
+ attrs: {
|
|
|
+ id: 'cancel'
|
|
|
},
|
|
|
- ]
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
+ text: 'Cancel'
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+}
|
|
|
|
|
|
- body['subTags'][1]['subTags'][1]['text']
|
|
|
- body['subTags'][0]['subTags'][1]['attrs']['id']
|
|
|
+body.subTags[1].subTags[1].text
|
|
|
+body.subTags[0].subTags[1].attrs.id
|
|
|
|
|
|
/* declarative fields */
|
|
|
|
|
|
var notebook = {
|
|
|
brand: prompt("Enter a brand"),
|
|
|
- type: prompt("Enter a type"),
|
|
|
+ type: prompt("Enter a type"),
|
|
|
model: prompt("Enter a model"),
|
|
|
ram: +prompt("Enter a ram"),
|
|
|
- size: +prompt("Enter a size"),
|
|
|
+ size: prompt("Enter a size"),
|
|
|
weight: +prompt("Enter a weight"),
|
|
|
resolution: {
|
|
|
width: +prompt("Enter a width"),
|
|
|
height: +prompt("Enter a height"),
|
|
|
},
|
|
|
- owner: {}
|
|
|
- };
|
|
|
-
|
|
|
- var phone = {
|
|
|
- brand: prompt("Enter a brand"),
|
|
|
- model: prompt("Enter a model"),
|
|
|
- ram: +prompt("Enter a ram"),
|
|
|
- color: prompt("Enter a color"),
|
|
|
- owner: {}
|
|
|
- };
|
|
|
-
|
|
|
-
|
|
|
- var person = {
|
|
|
- name: prompt("Enter a name"),
|
|
|
- surname: prompt("Enter a surname"),
|
|
|
- married: confirm("Are you a married?"),
|
|
|
- smartphone: {},
|
|
|
- laptop:{}
|
|
|
- }
|
|
|
+ owner: 'Anton'
|
|
|
+};
|
|
|
+
|
|
|
+var phone = {
|
|
|
+ brand: prompt("Enter a brand"),
|
|
|
+ model: prompt("Enter a model"),
|
|
|
+ ram: +prompt("Enter a ram"),
|
|
|
+ color: prompt("Enter a color"),
|
|
|
+ owner: 'Anton'
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+var person = {
|
|
|
+ name: prompt("Enter a name"),
|
|
|
+ surname: prompt("Enter a surname"),
|
|
|
+ married: confirm("Are you a married?"),
|
|
|
+ smartphone: 'iPhone',
|
|
|
+ laptop: 'Lenovo'
|
|
|
+}
|
|
|
|
|
|
/* object links */
|
|
|
|
|
|
- person.smartphone = phone
|
|
|
- person.laptop = notebook
|
|
|
- notebook.owner = person
|
|
|
- phone.owner = person
|
|
|
+person.smartphone = phone
|
|
|
+person.laptop = notebook
|
|
|
+notebook.owner = person
|
|
|
+phone.owner = person
|
|
|
|
|
|
/* imperative array fill 3 */
|
|
|
|
|
|
- let arr = []
|
|
|
- arr[0] = prompt('Напишите слово')
|
|
|
- arr[1] = prompt('Напишите слово')
|
|
|
- arr[2] = prompt('Напишите слово')
|
|
|
- alert(arr)
|
|
|
+let arr = []
|
|
|
+arr[0] = prompt('Напишите слово')
|
|
|
+arr[1] = prompt('Напишите слово')
|
|
|
+arr[2] = prompt('Напишите слово')
|
|
|
+alert(arr)
|
|
|
|
|
|
/* while confirm */
|
|
|
|
|
|
- let round;
|
|
|
- while (round != true) {
|
|
|
- round = confirm('Вы человек?');
|
|
|
- if (round){
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+let round;
|
|
|
+while (round != true) {
|
|
|
+ round = confirm('Вы человек?');
|
|
|
+ if (round) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
/* array fill */
|
|
|
|
|
|
- let arr1 = [];
|
|
|
- let arr2 = [];
|
|
|
- while (arr1) {
|
|
|
- arr2.push(arr1 = prompt("Введите что-то"));
|
|
|
- if (arr1 == null || false) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+let arr1 = [];
|
|
|
+let value;
|
|
|
+
|
|
|
+do {
|
|
|
+ value = prompt("Введите что-то")
|
|
|
+ if (value) {
|
|
|
+ arr1.push(value);
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+} while (value)
|
|
|
|
|
|
/* array fill nopush */
|
|
|
|
|
|
- let arr4 = [];
|
|
|
- for (let i = 0; i != null; i++) {
|
|
|
- arr4 = prompt('Напишите слово')
|
|
|
- if (arr4 == null || false) {
|
|
|
- break
|
|
|
- }
|
|
|
+let arr4 = [];
|
|
|
+let value1;
|
|
|
+
|
|
|
+for (let i = 0; i != null; i++) {
|
|
|
+ value1 = prompt('Напишите слово')
|
|
|
+
|
|
|
+ if (value1) {
|
|
|
+ arr4[i] = value1
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ break
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
/* infinite probability */
|
|
|
|
|
|
- let random = Math.random();
|
|
|
- let result = 0;
|
|
|
- while (random) {
|
|
|
- random = Math.random();
|
|
|
- result += 1;
|
|
|
- if (random > 0.9) {
|
|
|
- alert("Компьютер выполнил " + result + " циклов.");
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
+let random = Math.random();
|
|
|
+let result = 0;
|
|
|
+while (random) {
|
|
|
+ random = Math.random();
|
|
|
+ result += 1;
|
|
|
+ if (random > 0.9) {
|
|
|
+ alert("Компьютер выполнил " + result + " циклов.");
|
|
|
+ break
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
/* empty loop */
|
|
|
|
|
|
- do {
|
|
|
-
|
|
|
- } while(prompt('Напишите слово') == null || false)
|
|
|
+do {
|
|
|
+
|
|
|
+} while (prompt('Напишите слово') == null || false)
|
|
|
|
|
|
/* progression sum */
|
|
|
|
|
|
- var sum = 0;
|
|
|
- for (var i=1; i<=27; i=i+3) {
|
|
|
- console.log(i);
|
|
|
- sum=sum+i;
|
|
|
- }
|
|
|
- console.log(sum)
|
|
|
+var sum = 0;
|
|
|
+for (var i = 1; i <= 27; i = i + 3) {
|
|
|
+ console.log(i);
|
|
|
+ sum = sum + i;
|
|
|
+}
|
|
|
+console.log(sum)
|
|
|
|
|
|
/* chess one line */
|
|
|
|
|
|
- let chessStr = ' ';
|
|
|
- for (let i = 0; i < 10; i++) {
|
|
|
-
|
|
|
- if (i % 2 === 0){
|
|
|
- chessStr += " ";
|
|
|
- } else {
|
|
|
- chessStr += "#";
|
|
|
- }
|
|
|
-
|
|
|
+let chessStr = ' ';
|
|
|
+for (let i = 0; i < 10; i++) {
|
|
|
+
|
|
|
+ if (i % 2 === 0) {
|
|
|
+ chessStr += " ";
|
|
|
+ } else {
|
|
|
+ chessStr += "#";
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
console.log(chessStr)
|
|
|
|
|
|
/* numbers */
|
|
|
|
|
|
- let numbers;
|
|
|
- for (let i=0; i<=10; i++){
|
|
|
- for (let a=0; a<10; a++) {
|
|
|
- numbers = numbers + a;
|
|
|
- if (a == 9) {
|
|
|
- numbers = numbers + '\n' }
|
|
|
- }
|
|
|
- if (i == 10) {
|
|
|
- console.log(numbers);
|
|
|
- break;
|
|
|
- }
|
|
|
+let numbers;
|
|
|
+for (let i = 0; i <= 10; i++) {
|
|
|
+ for (let a = 0; a < 10; a++) {
|
|
|
+ numbers = numbers + a;
|
|
|
+ if (a == 9) {
|
|
|
+ numbers = numbers + '\n'
|
|
|
}
|
|
|
+ }
|
|
|
+ if (i == 10) {
|
|
|
+ console.log(numbers);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
/* chess */
|
|
|
|
|
|
let chess;
|
|
|
- for (let i = 0; i < 10; i++) {
|
|
|
- if(i > 0) chess += "\n";
|
|
|
- for (let j = 0; j < 12; j++) {
|
|
|
- if ((j + i) % 2 === 0){
|
|
|
- chess += ".";
|
|
|
- } else {
|
|
|
- chess += "#";
|
|
|
- }
|
|
|
- }
|
|
|
+for (let i = 0; i < 10; i++) {
|
|
|
+ if (i > 0) chess += "\n";
|
|
|
+ for (let j = 0; j < 12; j++) {
|
|
|
+ if ((j + i) % 2 === 0) {
|
|
|
+ chess += ".";
|
|
|
+ } else {
|
|
|
+ chess += "#";
|
|
|
}
|
|
|
- console.log(chess)
|
|
|
+ }
|
|
|
+}
|
|
|
+console.log(chess)
|
|
|
|
|
|
/* cubes */
|
|
|
|
|
|
- let index = [];
|
|
|
- for(let i = 0; i <= 10; i++) {
|
|
|
- index.push(i*i*i);
|
|
|
- }
|
|
|
+let index = [];
|
|
|
+for (let i = 0; i <= 10; i++) {
|
|
|
+ index.push(i * i * i);
|
|
|
+}
|
|
|
|
|
|
- console.log(index)
|
|
|
+console.log(index)
|
|
|
|
|
|
/* multiply table */
|
|
|
|
|
|
- let arr3 = []
|
|
|
- for (let i = 0; i<=10; i++) {
|
|
|
- let arr4 = []
|
|
|
- arr3.push(arr4)
|
|
|
- for (let a = 0; a <= 10; a++) {
|
|
|
- arr4.push(i * a)
|
|
|
- }
|
|
|
- }
|
|
|
- console.log(arr3)
|
|
|
+let arr3 = []
|
|
|
+for (let i = 0; i <= 10; i++) {
|
|
|
+ let arr4 = []
|
|
|
+ arr3.push(arr4)
|
|
|
+ for (let a = 0; a <= 10; a++) {
|
|
|
+ arr4.push(i * a)
|
|
|
+ }
|
|
|
+}
|
|
|
+console.log(arr3)
|
|
|
|
|
|
/* Задание на синий пояс: треугольник */
|
|
|
|
|
|
- let delta = '';
|
|
|
- for (let i = 0; i < 1; i++) {
|
|
|
- for (let j = 0; j <= 11; j++) {
|
|
|
- if (j == 11) {
|
|
|
- delta = delta + '\n'
|
|
|
- }
|
|
|
- else if(j === 5) {
|
|
|
- delta = delta + '#'
|
|
|
- }
|
|
|
- else {
|
|
|
- delta = delta + '.'
|
|
|
- }
|
|
|
- }
|
|
|
- for (let j = 0; j <= 11; j++) {
|
|
|
- if (j == 11) {
|
|
|
- delta = delta + '\n'
|
|
|
- }
|
|
|
- else if(j === 4 || j === 5 || j === 6) {
|
|
|
- delta = delta + '#'
|
|
|
- }
|
|
|
- else {
|
|
|
- delta = delta + '.'
|
|
|
- }
|
|
|
- }
|
|
|
- for (let j = 0; j <= 11; j++) {
|
|
|
- if (j == 11) {
|
|
|
- delta = delta + '\n'
|
|
|
- }
|
|
|
- else if(j === 3 || j === 4 || j === 5 || j === 6 || j === 7) {
|
|
|
- delta = delta + '#'
|
|
|
- }
|
|
|
- else {
|
|
|
- delta = delta + '.'
|
|
|
- }
|
|
|
- }
|
|
|
- for (let j = 0; j <= 11; j++) {
|
|
|
- if (j == 11) {
|
|
|
- delta = delta + '\n'
|
|
|
- }
|
|
|
- else if(j === 2 || j === 3 || j === 4 || j === 5 || j === 6 || j === 7 || j === 8) {
|
|
|
- delta = delta + '#'
|
|
|
- }
|
|
|
- else {
|
|
|
- delta = delta + '.'
|
|
|
- }
|
|
|
- }
|
|
|
- for (let j = 0; j <= 11; j++) {
|
|
|
- if (j == 11) {
|
|
|
- delta = delta + '\n'
|
|
|
- }
|
|
|
- else if(j === 1 || j === 2 || j === 3 || j === 4 || j === 5 || j === 6 || j === 7 || j === 8 || j === 9) {
|
|
|
- delta = delta + '#'
|
|
|
- }
|
|
|
- else {
|
|
|
- delta = delta + '.'
|
|
|
- }
|
|
|
- }
|
|
|
- for (let j = 0; j <= 11; j++) {
|
|
|
- if (j == 11) {
|
|
|
- delta = delta + '\n'
|
|
|
- }
|
|
|
- else if(j === 0 || j === 1 || j === 2 || j === 3 || j === 4 || j === 5 || j === 6 || j === 7 || j === 8 || j === 9 || j === 10) {
|
|
|
- delta = delta + '#'
|
|
|
- }
|
|
|
- else {
|
|
|
- delta = delta + '.'
|
|
|
- }
|
|
|
- }
|
|
|
+let delta = '';
|
|
|
+for (let i = 0; i < 1; i++) {
|
|
|
+ for (let j = 0; j <= 11; j++) {
|
|
|
+ if (j == 11) {
|
|
|
+ delta = delta + '\n'
|
|
|
+ }
|
|
|
+ else if (j === 5) {
|
|
|
+ delta = delta + '#'
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ delta = delta + '.'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (let j = 0; j <= 11; j++) {
|
|
|
+ if (j == 11) {
|
|
|
+ delta = delta + '\n'
|
|
|
+ }
|
|
|
+ else if (j === 4 || j === 5 || j === 6) {
|
|
|
+ delta = delta + '#'
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ delta = delta + '.'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (let j = 0; j <= 11; j++) {
|
|
|
+ if (j == 11) {
|
|
|
+ delta = delta + '\n'
|
|
|
+ }
|
|
|
+ else if (j === 3 || j === 4 || j === 5 || j === 6 || j === 7) {
|
|
|
+ delta = delta + '#'
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ delta = delta + '.'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (let j = 0; j <= 11; j++) {
|
|
|
+ if (j == 11) {
|
|
|
+ delta = delta + '\n'
|
|
|
+ }
|
|
|
+ else if (j === 2 || j === 3 || j === 4 || j === 5 || j === 6 || j === 7 || j === 8) {
|
|
|
+ delta = delta + '#'
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ delta = delta + '.'
|
|
|
}
|
|
|
+ }
|
|
|
+ for (let j = 0; j <= 11; j++) {
|
|
|
+ if (j == 11) {
|
|
|
+ delta = delta + '\n'
|
|
|
+ }
|
|
|
+ else if (j === 1 || j === 2 || j === 3 || j === 4 || j === 5 || j === 6 || j === 7 || j === 8 || j === 9) {
|
|
|
+ delta = delta + '#'
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ delta = delta + '.'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (let j = 0; j <= 11; j++) {
|
|
|
+ if (j == 11) {
|
|
|
+ delta = delta + '\n'
|
|
|
+ }
|
|
|
+ else if (j === 0 || j === 1 || j === 2 || j === 3 || j === 4 || j === 5 || j === 6 || j === 7 || j === 8 || j === 9 || j === 10) {
|
|
|
+ delta = delta + '#'
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ delta = delta + '.'
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- console.log(delta)
|
|
|
+console.log(delta)
|