Browse Source

HW<5> done

Polina-Kob 1 year ago
parent
commit
b8d19b42ff
1 changed files with 228 additions and 0 deletions
  1. 228 0
      js-04/index.html

+ 228 - 0
js-04/index.html

@@ -0,0 +1,228 @@
+<!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>HW-4</title>
+</head>
+
+<body>
+    <script>
+        //html tree  
+        let body = {
+            tegName: 'body',
+            subTags: [{
+                    tegName: 'div',
+                    subTags: [{
+                            tegName: 'span',
+                            text: 'Enter a data please',
+                        },
+                        {
+                            tegName: 'br',
+                        },
+                        {
+                            tegName: 'input',
+                            attrs: {
+                                type: 'text',
+                                id: 'name'
+                            },
+                        },
+                        {
+                            tegName: 'input',
+                            attrs: {
+                                type: 'text',
+                                id: 'surname'
+                            },
+                        },
+                    ]
+
+                },
+                {
+                    tagName: 'div',
+                    subTags: [{
+                            tegName: 'button',
+                            text: 'ok',
+                            attrs: {
+                                id: 'ok',
+                            }
+                        },
+                        {
+                            tegName: 'button',
+                            text: 'cancel',
+                            attrs: {
+                                id: 'cancel',
+                            }
+                        }
+                    ]
+                }
+            ]
+        }
+        //Выведите значения текста во второй кнопке, используя . и [].
+        body.subTags[1].subTags[1].text // 'cancel'
+        //Выведите значение атрибута id во втором input, используя . и [].
+        body.subTags[0].subTags[3].attrs.id // 'surname'
+
+
+        //declarative fields
+
+        let 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"),
+            },
+        };
+
+        let phone = {
+            brand: prompt("Enter a brand"),
+            model: prompt("Enter a model"),
+            ram: +prompt("Enter a ram"),
+            color: prompt("Enter a color"),
+        };
+
+        let person = {
+            name: prompt("Enter a name"),
+            surname: prompt("Enter a surname"),
+            married: confirm("Married ?"),
+            smartphone: { //object links
+                nameSmartphone: prompt("Enter a smartphone"),
+                owner: [person.name, person.surname],
+            },
+            laptop: {
+                nameLaptop: prompt("Enter a laptop"),
+                owner: [person.name, person.surname],
+            },
+        };
+
+        // imperative array fill 3
+
+        let box = [];
+        box[0] = prompt('Введите текст 1'),
+            box[1] = prompt('Введите текст 2'),
+            box[2] = prompt('Введите текст 3');
+        alert(box)
+
+        //while confirm
+
+        let container = confirm('Сделайте цикл с confirm, который продолжается по Отмена и заканчивается по ОК.')
+        while (container == false) {
+            alert("продолжение")
+            break;
+        }
+
+        //array fill
+        let arr = [];
+        let arr2 = []
+        while (arr) {
+            arr2.push(arr = prompt('text'))
+            if (arr === null) {
+                break;
+            }
+        }
+
+        //array fill nopush
+
+        let array = [];
+        for (let i = 0; i != null; i++) {
+            array[i] = prompt("text");
+            if (array[i] === null) {
+                break;
+            }
+
+        }
+
+        //infinite probability
+
+        let iterations = 0;
+        while (random) {
+            random = Math.random();
+            iterations++
+            if (random > 0.9) {
+                alert(random + " : число");
+                alert(iterations + " : количество итераций");
+                break;
+            }
+        }
+
+        //empty loop
+
+        do {
+
+        } while (prompt('Введите текст') != false)
+
+        //progression sum
+
+        let d = 3; // шаг или разность прогрессии.
+        //a1 = 1 - первый член
+        //s - сумма арифметической прогрессии
+        for (a1 = 1; n < 100; a1++) {
+            s = 1 / 2 * (2 * a1 + d * (n - 1)) * n;
+            alert("Сумма арифметической прогрессии S = " + s);
+            break;
+        }
+
+        //chess one line
+
+        let str = "";
+        for (i = 0; i < 11; i++) {
+            if (i % 2) {
+                str += "#"
+            } else {
+                str += " "
+            }
+        }
+        alert(str)
+
+        //numbers
+
+        let numbers = "";
+        for (let i = 0; i <= 9; i++) {
+            for (let x = 0; x <= 9; x++) {
+                numbers += x;
+                if (x == 9) {
+                    numbers += "\n"
+                }
+            }
+            if(i == 9){
+                console.log(numbers)
+            }
+        }
+
+        //chess
+
+        let chess = "";
+        for(i = 0; i >= 0; i++){
+            for(j = 0; j < 14; j++){
+                if(j == 13){
+                    chess += "\n"
+                }else if( j % 2 ){
+                    chess += "#"
+                }else {
+                    chess += "."
+                }
+            }
+            for(j = 0; j < 14; j++){
+                if(j == 13){
+                    chess += "\n"
+                }else if( j % 2 ){
+                    chess += "."
+                }else {
+                    chess += "#"
+                }
+            }
+            if (i == 3) {
+                    console.log(chess);
+                 }
+        }
+
+    </script>
+</body>
+
+</html>