Vika 2 years ago
parent
commit
5ece172ffc
3 changed files with 226 additions and 0 deletions
  1. 13 0
      js5/index.html
  2. 213 0
      js5/main.js
  3. 0 0
      js5/style.css

+ 13 - 0
js5/index.html

@@ -0,0 +1,13 @@
+<!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>
+  <link href="style.css" rel="stylesheet">
+</head>
+<body>
+  <script src="main.js"></script>
+</body>
+</html>

+ 213 - 0
js5/main.js

@@ -0,0 +1,213 @@
+//Task a
+// function a(b){
+//   alert(b);
+// }
+// a("Привет!"); 
+
+
+//Task cube
+// function cube(a){
+//   return (a*a*a);
+// }
+// cube(3);
+
+
+//Task avg2
+// function avg2 (a, b) {
+//   return ((a + b) / 2);
+// }
+//avg2(1,2) // возвращает 1.5
+//avg2(10,5) // возвращает 7.5
+
+
+
+//Task sum3
+// function sum3 (a, b, c = 0) { 
+//   return (a + b + c) ;
+// }
+// sum3(1,2,3) // => 6
+// sum3(5,10,100500) // => 100515
+// sum3(5,10) // => 15
+
+
+
+//Task intRandom
+// function intRandom (a, b) {
+//   let c = b - a;
+//   b ? b = a : a = 0;
+   
+//   if (a === b) {
+//     return a;
+//   }
+
+//   (b - a) ? c : c = a ;
+
+//   return(Math.round( Math.random() * c ));
+// }
+// intRandom(2,15) // возвращает целое случайное число от 2 до 15 (включительно)
+// intRandom(-1,-1) // вернет -1
+// intRandom(0,1) // вернет 0 или 1
+// intRandom(10) // вернет 0 до 10 включительно
+
+
+
+
+//Task greetAll
+// function greetAll (arg) {
+//   let str = `Hello`;
+//   for (let i of arguments) {
+//     str += ' ' + i + ','; 
+//   }
+//   str = str.slice(0, -1);
+//   alert(str);
+// }
+// greetAll("Superman");
+// greetAll("Superman", "SpiderMan");
+// greetAll("Superman", "SpiderMan", "Captain Obvious");
+
+
+
+//Task sum
+// function sum (...arg) {
+//   let acum = 0;
+//   for (let value of arg) {
+//     acum += value;
+//   } 
+//   return acum;
+// }
+// sum(1) // => 1
+// sum(2) // => 2
+// sum(10,20,40,100) // => 170
+
+
+// let sample = prompt("Введите название задания");
+
+// switch (sample.toLowerCase()) {
+
+//     case "a":  function a(b){
+//                  alert(b);
+//                }
+//               a("Привет!"); 
+//               break;
+
+//     case "cube": function cube(a) {
+//                   return (a*a*a);
+//                  }
+//                  cube(3);
+//                  break;
+
+//     case "avg2": function avg2 (a, b) {
+//                   return ((a + b) / 2);
+//                  }
+//                  avg2(1,2); 
+//                  avg2(10,5); 
+//                  break;
+
+//     case "sum3": function sum3 (a, b, c = 0) { 
+//                   return (a + b + c) ;
+//                  }
+//                  sum3(1,2,3); 
+//                  sum3(5,10,100500); 
+//                  sum3(5,10);
+//                  break;
+                 
+//     case "intrandom": function intRandom (a, b) {
+//                       let c = b - a;
+//                       b ? b = a : a = 0;
+                      
+//                       if (a === b) {
+//                         return a;
+//                       }
+                    
+//                       (b - a) ? c : c = a ;
+                    
+//                       return(Math.round( Math.random() * c ));
+//                       } 
+//                       intRandom(2,15); 
+//                       intRandom(0,1);
+//                       intRandom(10);
+//                       break;
+                      
+//     case "greetall": function greetAll (arg) {
+//                       let str = `Hello`;
+//                       for (let i of arguments) {
+//                         str += ' ' + i + ','; 
+//                       }
+//                       str = str.slice(0, -1);
+//                       alert(str);
+//                      }
+//                      greetAll("Superman");
+//                      greetAll("Superman", "SpiderMan");
+//                      greetAll("Superman", "SpiderMan", "Captain Obvious");
+//                      break;
+
+//     case "sum": function sum (...arg) {
+//                 let acum = 0;
+//                 for (let value of arg) {
+//                   acum += value;
+//                 } 
+//                 return acum;
+//                 }
+//                 sum(1);
+//                 sum(2);
+//                 sum(10,20,40,100);
+//                 break;
+// };
+
+let setFunction ={
+ "a": function (b){
+        alert(b);
+      },
+  "cube": function cube(a) {
+            return (a*a*a);
+          },
+  "avg2": function avg2 (a, b) {
+            return ((a + b) / 2);
+          },
+  "sum3": function sum3 (a, b, c = 0) { 
+            return (a + b + c) ;
+          },
+  "intrandom": function intRandom (a, b) {    
+                let c = b - a;
+                b ? b = a : a = 0;
+                
+                if (a === b) {
+                  return a;
+                }
+              
+                (b - a) ? c : c = a ;
+              
+                return(Math.round( Math.random() * c ));
+              },   
+  "greetall": function greetAll (arg) {            
+                let str = `Hello`;
+                for (let i of arguments) {
+                  str += ' ' + i + ','; 
+                }
+                str = str.slice(0, -1);
+                alert(str);
+              },
+  "sum": function sum (...arg) {
+          let acum = 0;
+          for (let value of arg) {
+            acum += value;
+          } 
+          return acum;
+         }
+};
+
+//setFunction.greetall("Вася, Петя")
+
+    
+                 
+                 
+
+    
+                 
+                 
+     
+
+                      
+                      
+    
+     

+ 0 - 0
js5/style.css