Helen 3 years ago
parent
commit
e2b1318db8
2 changed files with 110 additions and 0 deletions
  1. 12 0
      Функции/index.html
  2. 98 0
      Функции/js/script.js

+ 12 - 0
Функции/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>HW5</title>
+</head>
+<body>
+    <script src="js/script.js"></script>
+</body>
+</html>

+ 98 - 0
Функции/js/script.js

@@ -0,0 +1,98 @@
+"use strict";
+
+function a() {
+    return alert("Привет!");
+}
+
+function cube(num) {
+    return console.log(Math.pow(num, 3));
+}
+
+function avg2(a, b) {
+    return console.log((a + b) / 2)
+}
+
+function sum3(a, b, c) {
+    return console.log(a + b + c || a + b)
+}
+
+function intRandom(min, max) {
+    min = Math.ceil(min);
+    max = Math.floor(max);
+    return console.log(Math.floor(Math.random() * (max - min)) + min + 1 || Math.floor(Math.random() * min) + 1);
+}
+
+function greetAll() {
+    let ani = "Hello";
+    for (let key of arguments) {
+        ani = `${ani} ${key},`;
+    }
+    return alert(ani.substring(0, ani.length - 1))
+}
+
+function sum() {
+    let total = 0;
+    for (let key of arguments) {
+        total += key;
+    }
+    return console.log(total);
+}
+
+let task = prompt("Введите название задания", "");
+switch (task.toLocaleLowerCase()) {
+    case "a":
+        a();
+        break;
+    case "cube":
+        cube(3)
+        break;
+    case "avg2":
+        avg2(1, 2);
+        avg2(10, 5);
+        break;
+    case "sum3":
+        sum3(1, 2, 3);
+        sum3(5, 10, 100500);
+        sum3(5, 10);
+        break;
+    case "intrandom":
+        intRandom(2, 10);
+        break;
+    case "greetall":
+        greetAll("Superman");
+        greetAll("Superman", "SpiderMan");
+        greetAll("Superman", "SpiderMan", "Captain Obvious");
+        break;
+    case "sum":
+        sum(1);
+        sum(2);
+        sum(10, 20, 40, 100);
+        break;
+    default:
+        alert('Неизвестное значение');
+}
+
+function unionDeclarative() {
+    let task = {
+        a: () => a(),
+        cube: () => cube(3),
+        avg2: () => {
+            avg2(1, 2);
+            avg2(10, 5)
+        },
+        sum3: () => {
+            sum3(1, 2, 3);
+            sum3(5, 10, 100500);
+            sum3(5, 10);
+        },
+        intrandom: () => intRandom(2, 10),
+        greetall: () => {
+            greetAll("Superman");
+            greetAll("Superman", "SpiderMan");
+            greetAll("Superman", "SpiderMan", "Captain Obvious");
+        },
+        sum: () => sum(10, 20, 40, 100),
+    }
+    task[prompt("Введите название задания", "").toLocaleLowerCase()]();
+}
+// unionDeclarative()