فهرست منبع

Homework08 continue

GennadyBerg 2 سال پیش
والد
کامیت
44e2799b8f

+ 50 - 0
js/07/hw07_01literals.html

@@ -0,0 +1,50 @@
+<header>
+    <h1>Literals</h1>
+</header>
+
+<body>
+    <script>
+        const cat =
+        {
+            "head":
+            {
+                "name": "cat's head",
+                "ears":
+                    [
+                        {
+                            "name": "ear",
+                            "attrs":
+                            {
+                                "position": "left"
+                            }
+                        },
+                        {
+                            "name": "ear",
+                            "attrs":
+                            {
+                                "position": "right"
+                            }
+                        }
+                    ],
+                "eyes": [{ "name": "eye", "attrs": { "position": "left" } }, { "name": "eye", "attrs": { "position": "right" } }],
+                "mouth": "cat's"
+            },
+            "body":
+            {
+                "name": "cat's body",
+                "paws":
+                    [
+                        { "name": "paw", "attrs": { "position": "left", "placement": "front" } },
+                        { "name": "paw", "attrs": { "position": "right", "placement": "front" } },
+                        { "name": "paw", "attrs": { "position": "left", "placement": "rear" } },
+                        { "name": "paw", "attrs": { "position": "right", "placement": "rear" } },
+                    ],
+                "tail": "cat's tail"
+            }
+        }
+
+
+
+    </script>
+
+</body>

+ 33 - 0
js/07/hw07_02literals_expand.html

@@ -0,0 +1,33 @@
+<header>
+    <h1>Literals expand</h1>
+</header>
+
+<body>
+    <script>
+        const cat =
+        {
+            "head":
+            {
+                "name": "cat's head",
+                "ears": [{ "name": "ear", "attrs": { "position": "left" } }, { "name": "ear", "attrs": { "position": "right" } }],
+                "eyes": [{ "name": "eye", "attrs": { "position": "left" } }, { "name": "eye", "attrs": { "position": "right" } }],
+                "mouth": "cat's"
+            },
+            "body":
+            {
+                "name": "cat's body",
+                "paws":
+                    [
+                        { "name": "paw", "attrs": { "position": "left", "placement": "front" } },
+                        { "name": "paw", "attrs": { "position": "right", "placement": "front" } },
+                        { "name": "paw", "attrs": { "position": "left", "placement": "rear" } },
+                        { "name": "paw", "attrs": { "position": "right", "placement": "rear" } },
+                    ],
+                "tail": "cat's tail"
+            }
+        }
+        cat[prompt("Enter property name")] = prompt("Enter property value");
+        cat[prompt("Enter property name")] = prompt("Enter property value");
+    </script>
+
+</body>

+ 22 - 0
js/08/hw08_01_!Temperature.html

@@ -0,0 +1,22 @@
+<header>
+    <h1>Temperature</h1>
+</header>
+
+<body>
+    <script>
+        const tempConvert = (value, isCelsius) =>
+            isCelsius ? (temperVal - 32.0) * 5.0 / 9.0 : (temperVal * 9.0 / 5.0) + 32.0;
+
+        let temperStr = prompt("Enter please temperature with F or C ");
+        temperVal = temperStr.substring(0, temperStr.length - 1);
+        if (temperStr.charAt(temperStr.length - 1) == 'F') {
+            let temperCels = tempConvert(temperVal, true);
+            alert("Temperature in Celsius: " + temperCels.toFixed(1) + "C");
+        }
+        else {
+            let temperFahr = tempConvert(temperVal, false);
+            alert("Temperature in Fahrengeit: " + temperFahr.toFixed(1) + "F");
+        }
+    </script>
+
+</body>

+ 18 - 0
js/08/hw08_02_!RGB.html

@@ -0,0 +1,18 @@
+<header>
+    <h1>RGB</h1>
+</header>
+
+<body>
+    <script>
+        const RGB = (r, g, b) => {
+            let color = b + g * 256 + r * 256 * 256;
+            result = "#" + color.toString(16).toUpperCase().padStart(6, '0');
+            return result;
+        }
+
+        let red = +prompt("Enter red");
+        let green = +prompt("Enter green");
+        let blue = +prompt("Enter blue");
+        alert("color: " + RGB(red, green, blue));
+    </script>
+</body>

+ 17 - 0
js/08/hw08_03_!Flats.html

@@ -0,0 +1,17 @@
+<header>
+    <h1>Flats</h1>
+</header>
+
+<body>
+    <script>
+        const padikNum = (flatNum, floors = 9, flats = 4) => {
+            let entrance = Math.floor(flatNum / flats / floors) + 1;
+            let floor = Math.floor((flatNum - (entrance * 36)) / flats) + 1;
+            return { entrance, floor };
+        }
+        let flatNum = +prompt("Enter flat number");
+        let padikDef = padikNum(flatNum);
+        alert("Entrance: " + (padikDef.entrance) + ", Floor: " + (padikDef.floor));
+    </script>
+
+</body>

+ 23 - 0
js/08/hw08_04_!Credentials.html

@@ -0,0 +1,23 @@
+<header>
+    <h1>Credentials</h1>
+</header>
+
+<body>
+    <script>
+        const capitalize = str => {
+            str = str.toLowerCase().trim();
+            let result = str[0].toUpperCase() + str.slice(1);
+            return result;
+        }
+        const credentials = () => {
+            let sName = capitalize(prompt("Enter surname"));
+            let name = capitalize(prompt("Enter name"));
+            let fatherName = capitalize(prompt("Enter father name"));
+            let fullName = sName + ' ' + name + ' ' + fatherName;
+            return { name, sName, fatherName, fullName };
+        }
+        let res = credentials();
+        alert(res.name + "\n" + res.sName + "\n" + res.fatherName + "\n" + res.fullName);
+    </script>
+
+</body>

+ 12 - 0
js/08/hw08_05_!NewLine.html

@@ -0,0 +1,12 @@
+<header>
+    <h1>NewLine</h1>
+</header>
+
+<body>
+    <script>
+        const toMultiLine = (str) =>
+            str.split("\\n").join("\n");
+        alert(toMultiLine(prompt("Enter multiline string with '\\n' as new line.")));
+    </script>
+
+</body>

+ 12 - 0
js/08/hw08_06_!PromptOr.html

@@ -0,0 +1,12 @@
+<header>
+    <h1>Prompt Or</h1>
+</header>
+
+<body>
+
+    <script>
+        const promptOr = (promptQuery) =>
+            prompt(promptQuery) || "Cancelled";
+        alert(promptOr("Enter Age"));
+    </script>
+</body>

+ 23 - 0
js/08/hw08_07_!LoginPass.html

@@ -0,0 +1,23 @@
+<header>
+    <h1>Login and password</h1>
+</header>
+
+<body>
+    <script>
+        const chekCredentials = (rightLogin, rigthtPass) => {
+
+            let login = prompt("Enter login");
+            let valid = login === rightLogin;
+            if (valid) {
+                let pass = prompt("Enter password");
+                valid = pass === rigthtPass;
+            }
+            return valid;
+        }
+        if (chekCredentials("admin", "qwerty"))
+            alert("Congrats!!");
+        else
+            alert("wrong credentials!!! SUKA");
+    </script>
+
+</body>

+ 67 - 0
js/08/hw08_08_!ForTable.html

@@ -0,0 +1,67 @@
+<header>
+    <h1>For Table</h1>
+</header>
+<style>
+    td {
+        padding: 5px;
+    }
+
+    td,
+    th {
+        border: 1px solid #999;
+        border-top-color: rgb(153, 153, 153);
+        border-top-style: solid;
+        border-top-width: 1px;
+        border-right-color: rgb(153, 153, 153);
+        border-right-style: solid;
+        border-right-width: 1px;
+        border-bottom-color: rgb(153, 153, 153);
+        border-bottom-style: solid;
+        border-bottom-width: 1px;
+        border-left-color: rgb(153, 153, 153);
+        border-left-style: solid;
+        border-left-width: 1px;
+        border-image-source: initial;
+        border-image-slice: initial;
+        border-image-width: initial;
+        border-image-outset: initial;
+        border-image-repeat: initial;
+    }
+
+    td {
+        display: table-cell;
+        vertical-align: inherit;
+    }
+
+    table {
+        border-collapse: collapse;
+        text-indent: initial;
+        border-spacing: 2px;
+    }
+</style>
+
+<body>
+    <script>
+        const toHtmlTable = (arr) => {
+            let str = "<table>";
+            for (let arrEl of arr) {
+                str += "<tr>";
+                for (let val of arrEl) {
+                    str += `<td>${val}</td>`;
+                }
+                str += "</tr>";
+            }
+            str += "</table>";
+            return str;
+        }
+
+        arr = [];
+        for (let i = 0; i < 5; i++) {
+            arr[i] = [];
+            for (let j = 0; j < 5; j++) {
+                arr[i][j] = (i + 1) * (j + 1);
+            }
+        }
+        document.write(toHtmlTable(arr));
+    </script>
+</body>

+ 17 - 0
js/08/hw08_09_!FilterLexics.html

@@ -0,0 +1,17 @@
+<header>
+    <h1>filter Lexis</h1>
+</header>
+
+<body>
+    <script>
+        const lexis = (str, badWords) =>
+            !badWords.includes(str);
+
+        const lexisFilter = (str, badWords) =>
+            str.trim().split(' ').filter(w => lexis(w, badWords)).join(' ');
+
+        const lexx = ['бляха', 'муха', "пляха", "шабля"];
+        let phrase = lexisFilter(prompt("Enter a phrase"), lexx);
+        alert(phrase);
+    </script>
+</body>

+ 58 - 0
js/08/hw08_10_CurrencyTable.html

@@ -0,0 +1,58 @@
+<header>
+    <h1>Currency Table</h1>
+</header>
+
+<body>
+    <script>
+        const toHtmlTable = (arr) => {
+            let str = "<table>";
+            for (let arrEl of arr) {
+                str += "<tr>";
+                for (let val of arrEl) {
+                    str += `<td>${val}</td>`;
+                }
+                str += "</tr>";
+            }
+            str += "</table>";
+            return str;
+        }
+        
+        const createCurrencyTable = () => {
+            fetch(`https://open.er-api.com/v6/latest/USD`)
+                .then(response => response.json())
+                .then(data => {
+                    const name = 0;
+                    const value = 1;
+                    let str = "<table>";
+                    arr = Object.entries(data.rates);
+                    str += "<tr><td></td>";
+                    for (let i = 0; i < arr.length; i++) {
+                        str += `<td>${arr[i][name]}</td>`;
+                    }
+                    str += "</tr>";
+                    for (let i = 0; i < arr.length; i++) {
+                        str += `<tr><td>${arr[i][name]}</td>`;
+                        currRate1 = arr[i][value];
+
+
+
+                        for (let j = 0; j < arr.length; j++) {
+                            currRate2 = arr[j][value];
+                            crossCurrRate = currRate2 / currRate1;
+                            str += `<td>${crossCurrRate.toFixed(3)}</td>`;
+                        }
+
+
+                        str += "</tr>";
+                    }
+                    str += "</table>";
+
+
+                    document.write(str);
+                });
+        }
+
+
+    </script>
+
+</body>

+ 32 - 0
js/08/hw08_11_Form.html

@@ -0,0 +1,32 @@
+<header>
+    <h1>Literals</h1>
+</header>
+
+<body>
+    <script>
+        
+    </script>
+
+</body>
+
+obj = {
+    "Name": "chevrolet chevelle malibu",
+    "Cylinders": 8,
+    "Displacement": 307,
+    "Horsepower": 130,
+    "Weight_in_lbs": 3504,
+    "Origin": "USA",
+    "in_production": false
+}
+
+const typesMap = { 'boolean': 'checkbox', 'number': 'number', 'string': 'text' };
+let str = "<form>\n"
+for (var name in obj) {
+    value = obj[name];
+    type = typeof value;
+    htmlType = typesMap[type];
+    str += `   <label>${name}: <input type="${htmlType}" value="${value}" /></label>\n`;
+}
+str += "<form>"
+document.write(str)
+alert(str)

+ 18 - 0
js/08/hw08_12_ArrayOfObj.html

@@ -0,0 +1,18 @@
+<header>
+    <h1>Literals</h1>
+</header>
+
+<body>
+    <script>
+        var persons = [
+    {name: "Иван", age: 17},
+    {name: "Мария", age: 35},
+    {name: "Алексей", age: 73},
+    {name: "Яков", age: 12},
+]
+
+sort(persons, "age"); //сортирует по возрасту по возрастанию
+sort(persons, "name", false); //сортирует по имени по убыванию
+    </script>
+
+</body>

+ 75 - 0
js/08/hw08_13_Table.html

@@ -0,0 +1,75 @@
+<header>
+    <h1>Literals</h1>
+</header>
+
+<body>
+    <script>
+        
+    </script>
+
+</body>
+
+var arr = [
+            {
+                "Name": "chevrolet chevelle malibu",
+                "Cylinders": 8,
+                "Displacement": 307,
+                "Horsepower": 130,
+                "Weight_in_lbs": 3504,
+                "Origin": "USA"
+            },
+            {
+                "Name": "buick skylark 320",
+                "Miles_per_Gallon": 15,
+                "Cylinders": 8,
+                "Displacement": 350,
+                "Horsepower": 165,
+                "Weight_in_lbs": 3693,
+                "Acceleration": 11.5,
+                "Year": "1970-01-01",
+            },
+            {
+                "Miles_per_Gallon": 18,
+                "Cylinders": 8,
+                "Displacement": 318,
+                "Horsepower": 150,
+                "Weight_in_lbs": 3436,
+                "Year": "1970-01-01",
+                "Origin": "USA"
+            },
+            {
+                "Name": "amc rebel sst",
+                "Miles_per_Gallon": 16,
+                "Cylinders": 8,
+                "Displacement": 304,
+                "Horsepower": 150,
+                "Year": "1970-01-01",
+                "Origin": "USA"
+            },
+        ]
+        names = Object
+            .entries(
+                arr.reduce(
+                    (prev, next) => {
+                        return { ...prev, ...next };
+                    }
+                ))
+            .map(entry => entry[0]);
+        str = "<table>";
+        str += "<tr>" +
+            names
+                .map(name => `<td>${name}</td>`)
+                .join('') +
+            "</tr>";
+        str +=
+                arr
+                    .map(obj => 
+                        `<tr>${
+                            names
+                                .map(name => `<td>${obj[name] || "-"}</td>`)
+                                .join('')
+                        }</tr>`)
+                    .join('');
+        str += "</table>";
+
+        document.write(str)

+ 28 - 0
js/08/hw08_14_Divide.html

@@ -0,0 +1,28 @@
+<header>
+    <h1>Literals</h1>
+</header>
+
+<body>
+    <script>
+        
+    </script>
+
+</body>
+
+
+<input type='number' id="firstNumber" />
+<input type='number' id="secondNumber" />
+<div id="divisionResult">
+    текст в div
+</div>
+<script>
+    const calcResult = () => {
+        console.log(firstNumber.value, secondNumber.value, divisionResult.innerHTML)
+        divisionResult.innerHTML = "Текст в <code>div</code> поменян с помощью <strong>Javascript</strong><br/>" + Math.random()
+    }
+    
+    firstNumber.oninput = secondNumber.oninput = calcResult
+</script>
+
+
+

+ 10 - 0
js/08/hw08_15_Calc Func.html

@@ -0,0 +1,10 @@
+<header>
+    <h1>Literals</h1>
+</header>
+
+<body>
+    <script>
+        
+    </script>
+
+</body>

+ 10 - 0
js/08/hw08_16_CalcLive.html

@@ -0,0 +1,10 @@
+<header>
+    <h1>Literals</h1>
+</header>
+
+<body>
+    <script>
+        
+    </script>
+
+</body>