Browse Source

HW<6> done

Levshin95 1 year ago
parent
commit
aed818ae63
3 changed files with 183 additions and 0 deletions
  1. 12 0
      HW6/index.html
  2. 129 0
      HW6/index.js
  3. 42 0
      training.html

+ 12 - 0
HW6/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>Document</title>
+</head>
+<body>
+    <script src="index.js"> </script>
+</body>
+</html>

+ 129 - 0
HW6/index.js

@@ -0,0 +1,129 @@
+/* a */
+
+    function a(text){
+        alert(text)
+    }
+    a("Привет!")
+
+/* cube */
+
+    function cube(number){
+        return number ** 3
+    }
+    let result = cube(prompt('Enter a number'))
+    console.log(result)
+
+/* avg2 */
+
+    function avg2(a1, b1) {
+        return (a1 + b1) / 2
+    }
+    let a1 = +prompt('Enter a number')
+    let b1 = +prompt('Enter a number')
+    avg2(a1, b1)
+
+/* sum3 */
+
+    function sum3(a2, b2, c2) {
+        return a2 + b2 + c2 
+    }
+    let a2 = +prompt('Enter a number')
+    let b2 = +prompt('Enter a number')
+    let c2 = +prompt('Enter a number')
+    sum3(a2, b2, c2)
+
+/* intRandom */
+
+    function intRandom(a3, b3) {
+        let random = Math.random()* (b3-a3) + a3
+        return Math.round(random)
+    }
+    let a3 = +prompt('Enter a number')
+    let b3 = +prompt('Enter a number')
+    intRandom(a3, b3)
+
+/* greetAll */
+
+    function greetAll() {
+        for (let i = 0; i < arguments.length; i++) {
+            alert("Hello, " + arguments[i]);
+        }
+    }
+
+    greetAll(prompt('Enter a name'))
+
+/* sum */
+
+    function sum(a4, b4, c4) {
+        let sum = 0;
+        for (let i = 0; i < arguments.length; i++) {
+            sum += arguments[i];
+        }
+        return sum
+        
+    }
+    a4 = +prompt('Enter a number')
+    b4 = +prompt('Enter a number')
+    c4 = +prompt('Enter a number') 
+    sum(a4, b4, c4)
+
+/* Union */
+
+    function aSample(){
+        a("Привет!") 
+    }
+    
+    function cubeSample(){
+        cube(5) 
+    }
+    
+    function avg2Sample(){
+        avg2(2, 2)
+    }
+    
+    function sum3Sample(){
+        sum3(1, 2, 3)
+    }
+    
+    function intRandomSample(){
+        intRandom(2,10)
+    }
+    
+    function greetAllSample() {
+        greetAll('Superman')
+    }
+    
+    function sumSample(){
+        sum(1,4,7)
+    }
+    
+    
+    var sample = prompt("Введите название задания")
+    switch (sample.toLowerCase()){
+        case "a": aSample()
+                  break;
+        case "cube": cubeSample()
+                  break;
+        case "avg2": avg2Sample()
+                  break;
+        case "sum3": sum3Sample()
+                  break;
+        case "intRandom": intRandomSample()
+                  break;
+        case "greetAll": greetAllSample()
+                  break;
+        case "sum": sumSample()
+                  break;
+    }
+
+/* Union declarative */
+
+    let unionDeclarative = {
+        a: aSample(),
+        cube: cubeSample(),
+        avg2: avg2Sample(),
+        sum3: sum3Sample(),
+        intRandom: intRandomSample(),
+        greetAll: greetAllSample(),
+        sum: sumSample()
+    }  

+ 42 - 0
training.html

@@ -9,10 +9,52 @@
 <body>
 <script>
 
+function aSample(){
+    a("Привет!") 
+}
 
+function cubeSample(){
+    cube(5) 
+}
 
+function avg2Sample(){
+    avg2(2, 2)
+}
 
+function sum3Sample(){
+    sum3(1, 2, 3)
+}
 
+function intRandomSample(){
+    intRandom(2,10)
+}
+
+function greetAllSample() {
+    greetAll('Superman')
+}
+
+function sumSample(){
+    sum(1,4,7)
+}
+
+
+var sample = prompt("Введите название задания")
+switch (sample.toLowerCase()){
+    case "a": aSample()
+              break;
+    case "cube": cubeSample()
+              break;
+    case "avg2": avg2Sample()
+              break;
+    case "sum3": sum3Sample()
+              break;
+    case "intRandom": intRandomSample()
+              break;
+    case "greetAll": greetAllSample()
+              break;
+    case "sum": sumSample()
+              break;
+}
 </script>
 </body>
 </html>