Browse Source

structures_loops

Iryna Bolbat 2 years ago
parent
commit
3e70e19032
2 changed files with 228 additions and 0 deletions
  1. 12 0
      js_03_structures_loops/index.html
  2. 216 0
      js_03_structures_loops/main.js

+ 12 - 0
js_03_structures_loops/index.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script src="main.js"></script>
+</body>
+</html>

+ 216 - 0
js_03_structures_loops/main.js

@@ -0,0 +1,216 @@
+//1.html tree
+// let 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'
+//             }
+//         ]}
+//     ]
+// };
+// console.log(body.subTags[1].subTags[1].text);
+// console.log(body.subTags[0].subTags[3].attrs.id);
+
+//2.declarative fields, 3.object links
+// let person = {
+//     name : prompt('Your name?', ""),
+//     age : prompt('How old are you?', ""),
+//     pets : confirm('Do you have pets?'),
+//     car : confirm('Do you have a car?'),
+//     education : {
+//         school : prompt('When did you finished school?', ""),
+//         university : confirm('Are you studing in university'),
+//         sub : prompt('What are you studing or were studing in university?', "")
+//     },
+//     parents : {
+//         mother : prompt('What is your mother name?', ""),
+//         father : prompt('What is your father name?', "")
+//     },
+//     family : confirm('Do you have brother or sister?')
+// };
+
+// person.smartphone = new Object ({smartphone_name : prompt('Which smartphone do you have?', ""), smartphone_owner : confirm('Are you owner of this smartphone?')});
+// person.laptop = new Object ({laptop_name : prompt('Which laptop do you have?', ""), laptop_owner : confirm('Are you owner of this laptop?')});
+
+// console.log(person);
+
+//3.imperative array fill 3
+// let arr = [];
+// arr[0] = prompt('Name?');
+// arr[1] = prompt('Age?');
+// arr[2] = prompt('City?');
+// console.log(arr);
+
+//4.while confirm
+// let qw = confirm('Are you here?');
+// while (qw == false) {
+//     confirm('Are you here?');
+//     if(qw == true) {
+//         break;
+//     }
+// }
+
+//5.array fill
+// let arr = [];
+// let el = prompt('Which color?', '');
+// while(el !== null) {
+//     arr.push(el);
+//     el = prompt('Which color?', '');
+// }
+// console.log(arr);
+
+//6.array fill nopush
+// let arr = [];
+// let el = prompt('Which color?', '');
+// let i = 0;
+// while(el !== null) {
+//     arr[i] = el;
+//     el = prompt('Which color?', '');
+//     i++;
+// }
+// console.log(arr);
+
+//7.infinite probability
+// let rand = Math.random();
+// let x = 0;
+// while (true){
+//     x++;
+//     rand = Math.random();
+//     if(rand > 0.9) {
+//         break;
+//     }
+// }
+// alert(`Количество итераций: ${x}`);
+// console.log(rand);
+
+//8.empty loop
+// let promptValue = prompt('smth');
+// while(promptValue === null){
+//     x = prompt('smth');
+//     if (promptValue !== null) {
+//         break;
+//     }
+// }
+
+//9.progression sum
+// let sum = 0;
+// function countSum (n) {
+//     for (let i = 1; i < n; i += 3) {
+//         sum += i;
+//     }
+//     return sum;
+// }
+// console.log(countSum(10));
+
+//10.chess one line
+// let str = '';
+// for(let i = 0 ; i < 15; i++) {
+//     str += '# ';
+// }
+// console.log(str);
+
+//11.numbers
+// let str = '';
+// for(let r = 0; r < 10; r++){
+//     for(let c = 0; c < 10; c++){
+//         str += c;
+//     }
+//     str += '\n';
+// }
+// console.log(str);
+
+//12.chess
+// let str = '';
+// for(let i = 0; i < 10; i++){
+//     for(let x = 0; x < 6; x++){
+//         i % 2 == 0 ? (str += '#.') : (str += '.#');
+//     }
+//     str += '\n';
+// }
+// console.log(str);
+
+//13.cubes
+// function cube(n){
+//     let arr = [];
+//     for(let i = 0; i < n; i++){
+//         let cub = i*i*i;
+//         arr.push(cub);
+//     }
+//     return arr;
+// }
+// console.log(cube(10));
+
+//14.multiply table
+// let arr = [];
+// for(let i = 0; i < 10; i++){
+//     arr[i] = [];
+//     for(let x = 0; x < 10; x++){
+//         arr[i] [x] = i * x;
+//     }
+// }
+// console.log(arr);
+
+
+//15.matrix to html table
+// let str = '<table>';
+// for(let i = 1; i < 10; i++){
+//     str += '<tr>';
+//     for(let x = 1; x < 10; x++){
+//         str += '<td>';
+//         str += i*x;
+//         str += '</td>';
+//     }
+//     str += '</tr>';
+// }
+// str += '</table>';
+// document.write(str);
+// console.log(str);
+
+//16.Задание на синий пояс: Треугольник
+// function triangle (lineLenght, lines = 7){
+//     let start = Math.trunc(lineLenght / 2);
+//     let end = Math.trunc(lineLenght / 2);
+//     let str = '';
+//     for(let i = 0 ; i < lines; i++){
+//         for(let x = 0; x < lineLenght; x++){
+//             if(x < start || x > end){
+//                 str += '.';
+//             }
+//             else {
+//                 str += '#';
+//             }
+//         }
+//         str += '\n';
+//         start -= 1;
+//         end += 1;
+//     }
+//     return str;
+// }
+// console.log(triangle(20, 11));