Browse Source

HW<6> done

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

+ 129 - 0
js-06/index.html

@@ -0,0 +1,129 @@
+<!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-6</title>
+</head>
+
+<body>
+    <script>
+        //a
+
+        function a() {
+            alert("привет!!!")
+        }
+        a()
+
+        //cube 
+
+        function cube(a) {
+            return a ** 3;
+        }
+        alert(cube());
+        alert(cube(3));
+
+        //avg2
+
+        function avg2(a, b) {
+            return (a + b) / 2;
+        }
+        alert(avg2(1, 2))
+        alert(avg2(10, 5))
+
+        //sum3
+
+        function sum3(a, b, c) {
+            a = a || 0
+            b = b || 0
+            c = c || 0
+            return (a + b + c)
+        }
+        alert(sum3(1, 2, 3));
+        alert(sum3(5, 10, 100500));
+        alert(sum3(5, 10));
+
+        //intRandom
+
+        function intRandom(a, b) {
+            a = a || 0
+            b = b || 0
+            return Math.round(Math.random() * (b - a) + a);
+        }
+        alert(intRandom(2, 15));
+        alert(intRandom(-1, -1));
+        alert(intRandom(0, 1));
+        alert(intRandom(10));
+
+        //greetAll
+
+        function greetAll(...params) {
+            let add = "";
+            for (i = 0; i < params.length; i++) {
+                add += params[i] + " "
+            }
+            return alert("Hello " + add)
+        }
+        greetAll("Superman")
+        greetAll("Superman", "SpiderMan")
+        greetAll("Superman", "SpiderMan", "Captain Obvious")
+
+        //sum
+
+        function sum(...numbers) {
+            var sum = 0;
+            for (i = 0; i < numbers.length; i++) {
+                sum += numbers[i];
+            }
+            return sum;
+        }
+        alert(sum(1))
+        alert(sum(2))
+        alert(sum(10, 20, 40, 100))
+
+        //Union
+
+        var sample = prompt("Введите название задания")
+        switch (sample.toLowerCase()) {
+            case "a":
+                a()
+                break
+            case "cube":
+                cube()
+                break
+            case "avg2":
+                avg2()
+                break;
+            case "sum3":
+                sum3()
+                break;
+            case "intRandom":
+                intRandom()
+                break;
+            case "greetAll":
+                greetAll()
+                break
+            case "sum":
+                sum()
+                break;
+        }
+
+        //Union declarative
+       
+        let sample2 = {
+            a: a(),
+            cube: cube(),
+            avg2: avg2(),
+            sum3: sum3(),
+            intRandom: intRandom(),
+            greetAll: greetAll(),
+            sum: sum(),
+        }
+        //alert(sample2[prompt("Введите название задания")]);
+        
+    </script>
+</body>
+
+</html>