Евгения Акиншина před 3 roky
rodič
revize
10a72816df
2 změnil soubory, kde provedl 272 přidání a 0 odebrání
  1. 25 0
      js04/index.html
  2. 247 0
      js04/js/main.js

+ 25 - 0
js04/index.html

@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=\, initial-scale=1.0">
+    <link rel="stylesheet" href="css/style.css">
+    <title>HW4</title>
+</head>
+<body>
+    <table>
+        <script language="JavaScript"> 
+            document.write("<h1>Таблица умножения</h1>"); 
+            for (let j = 1; j <= 9; j++){  
+                document.write("<div style='float: left; width: 70px;'>"); 
+            for (let i = 1; i <=9; i++){ 
+                document.write(i + "*" + j + "=" +(i*j) + "<br>"); 
+            }  
+                document.write ("</div>"); 
+            } 
+        </script> 
+    </table>
+    <script src='js/main.js'></script>
+</body>
+</html>

+ 247 - 0
js04/js/main.js

@@ -0,0 +1,247 @@
+// html tree
+let body = {
+    name: 'body',
+    children: [
+        {
+            name: 'div',
+            children: [
+                {
+                    name: 'span',
+                    children: 'Enter a data please',
+                },
+                {
+                    name: 'br',
+                },
+                {
+                    name: 'input',
+                    attrs: {
+                        type: 'text',
+                        id: 'name',
+                    },
+                },
+                {
+                    name: 'input',
+                    attrs: {
+                        type: 'text',
+                        id: 'name',
+                    },
+                },
+            ]
+        },
+        {
+            name: 'div',
+            children: [
+                {
+                    name: 'button',
+                    attrs: {
+                        id: 'ok',
+                        children: 'OK',
+                    }
+                },
+                {
+                    name: 'button',
+                    attrs: {
+                        id: 'cancel',
+                        children: 'Cancel',
+                    }
+                },
+            ]
+        }
+    ],
+};
+
+// declarative fields
+let notebook = {
+    brand: prompt("Enter laptop brand: ") || "HP",
+    type: prompt("Enter laptop type: ") || "440 G4",
+    model: prompt("Enter your laptop model: ") || "Y7Z75EA",
+    ram: +prompt("Enter the amount of laptop RAM: ") || 4,
+    size: prompt("Enter laptop size: ") || 14,
+    weight: +prompt("Enter the weight of the laptop: ") || 1.8,
+
+    resolution: {
+        width: +prompt("Enter the width of the laptop: ") || 1920,
+        height: +prompt("Enter the length of the laptop: ") || 1080,
+    },
+};
+
+let phone = {
+    brand: prompt("Enter phone name: ") || "meizu",
+    model: prompt("Enter your phone model: ") || "m2",
+    ram: +prompt("Enter the amount of RAM: ") || 2,
+    color: prompt("Enter color: ") || "black",
+};
+let person = {
+    name: prompt("Enter a name: ") || "Donald",
+    surname: prompt("Enter a surname: ") || "Trump",
+    married: confirm("Are you married?") || true,
+};
+
+// object links
+person["smartphone"] = smartphone;
+person["laptop"] = laptop; 
+laptop["owner"] = person; 
+smartphone["owner"] = person; 
+
+//or
+person.smartphone = smartphone;
+person.laptop = laptop; 
+laptop.owner = person; 
+smartphone.owner = person; 
+
+// imperative array fill 3
+let arr = []; 
+
+alert("Введите названия ваших любимых фруктов: ")
+arr[0] = prompt("Первый фрукт: ");
+arr[1] = prompt("Второй фрукт: ");
+arr[2] = prompt("Третий фрукт: ");
+alert(arr + " " + "я це люблю!");
+
+// while confirm
+while (true) {
+    var a = confirm();
+    if (a === true || a == null) break;
+}
+
+// array fill
+let arrayValue = [];
+let elementPush;
+
+while (elementPush !== null) {
+    elementPush = prompt("Enter element: ");
+
+    if (elementPush === null) {
+        break;
+    }
+
+    arrayValue.push(elementPush);
+}
+console.log(arrayValue);
+
+// array fill nopush
+let elementAdd = [];
+
+for (let i = 0, j; j !== null; i++) {
+    j = prompt("Enter element: ");
+
+    if (j === null) {
+        break;
+    }
+
+    elementAdd[i] = j;
+}
+console.log(elementAdd);
+
+// infinite probability
+var i = 0;
+while (true) {
+    if (Math.random() > 0.9) {
+    alert(++i);
+    break;
+    }
+    else i++;
+}
+
+// empty loop
+let choiceUser;
+do {
+    choiceUser = prompt("ОK или Отмена?");
+} while (choiceUser != "");
+
+// progression sum
+var functionResult = '';
+n = +prompt("Введите N:");
+for (let i=1; i<=n; i= i+3) {
+functionResult = functionResult + i + ' ';
+}
+console.log(functionResult);
+
+// chess one line
+let str = ' ';
+
+for (let i = 0;i<10;i++)
+  if (i % 2 === 1) {
+        str += ' '
+    }
+    else {
+        str += '#'
+    }
+" # # # # # "
+// or
+let str = ' ';
+
+for(let i = 0;i<10;i++)
+  if (i % 2 === 0) {
+        str += '#'
+    }
+    else {
+        str += ' '
+    }
+" # # # # # "
+
+// numbers
+let str = '';
+
+for (let i=0;i<10;i++) {
+	for (j=0;j<10;j++) {
+		str += String(j); //or new String - преобразовано в строку с помощью глобального объекта напрямую
+	}
+    str += "\n";
+}
+console.log(str);
+
+// chess 1
+let a=12, b=10, str=''; // b-строки, a-символы, размер доски можно легко менять - изменяя значения a и b
+while (b--) str += (b%2?'#.':'.#').repeat(a/2)+((a%2)?b%2?'#':'.':'')+'\n';
+console.log(str);
+
+// cubes
+let enteredValue = prompt("Укажите число N для вычисления куба: ");
+let arrayValue = [];
+
+for (let i = 0; i < enteredValue; i++) {
+    arrayValue[i] = Math.pow(i, 3);
+}
+console.log(arrayValue);
+
+// multiply table
+var result = 'x ';
+for (var i = 0; i < 11; i++) {
+
+    for (var j = 0; j < 11; j++) {
+
+        if (i == 0 && j > 0) {
+          result += '[' + j + ']';
+        } 
+        else if (j == 0 && i>0) {
+          result += '[' + i + '] ';
+        } 
+        else if (i>0 && j>0) {
+        result += (i*j) + ' ';
+        }
+    }
+    result += '\n'
+}
+alert(result);
+
+// matrix to html table
+//Решение в html - зайти в html - Open with Live Server//
+
+// Задание на синий пояс: Треугольник
+
+// option 1
+function pyramid(n){
+    for (let i=1; i<= n; i++) {
+    let str = '.'.repeat(n-i);
+    let str2 = '#'. repeat(i*2 -1);
+    console.log(str + str2 + str);
+    }
+}
+pyramid(6);
+
+// option 2
+var lines = line = 6;
+a='.';
+b='#';
+while (line-->0) console.log(Array(line+1).join(a) +Array(2*(lines-line)).join(b) +Array(line+1).join(a));