|
@@ -0,0 +1,87 @@
|
|
|
+//a
|
|
|
+let a = function(str) {
|
|
|
+ alert(str);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//cube
|
|
|
+let cube = function(number) {
|
|
|
+ return Math.pow(number, 3);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//avg2
|
|
|
+let getMeanValue = function(numberA, numberB) {
|
|
|
+ return (numberA + numberB) / 2;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//sum3
|
|
|
+let sum3 = function(number1 = 0, number2 = 0, number3 = 0) {
|
|
|
+ return number1 + number2 + number3;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//intRandom
|
|
|
+let intRandom = function(bottomValue, topValue) {
|
|
|
+ return (Math.random() * topValue + bottomValue);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//greetAll
|
|
|
+let greetAll = function(...name) {
|
|
|
+ alert(`Hello ${name.join(", ")}`);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//sum
|
|
|
+let sum = function(...arr) {
|
|
|
+ let sumArrElement = 0;
|
|
|
+
|
|
|
+ for(let item of arr) {
|
|
|
+ sumArrElement += item;
|
|
|
+ }
|
|
|
+
|
|
|
+ return sumArrElement;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//Union
|
|
|
+var sample = prompt("Введите название задания");
|
|
|
+switch (sample.toLowerCase()){
|
|
|
+ case "a": a("Привет");
|
|
|
+ break;
|
|
|
+ case "cube": console.log(cube(5));
|
|
|
+ break;
|
|
|
+ case "avg2": console.log(getMeanValue(10, 5));
|
|
|
+ break;
|
|
|
+ case "sum3": console.log(sum3(5, 10));
|
|
|
+ break;
|
|
|
+ case "intRandom": console.log(intRandom(2, 15));
|
|
|
+ console.log(intRandom(-1, -1));
|
|
|
+ console.log(intRandom(0, 1));
|
|
|
+ console.log(intRandom(0, 10));
|
|
|
+ break;
|
|
|
+ case "greetAll": greetAll("Superman");
|
|
|
+ greetAll("Superman", "SpiderMan");
|
|
|
+ greetAll("Superman", "SpiderMan", "Captain Obvious");
|
|
|
+ break;
|
|
|
+ case "sum": console.log(sum(1)); // => 1
|
|
|
+ console.log(sum(2)); // => 2
|
|
|
+ console.log(sum(10,20,40,100)); // => 170
|
|
|
+ break;
|
|
|
+ default: alert("Такого задания нет");
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//Union declarative
|
|
|
+let arr = {
|
|
|
+ a: a("Привет"),
|
|
|
+ cube: console.log(cube(5)),
|
|
|
+ avg2: console.log(getMeanValue(10, 5)),
|
|
|
+ sum3: console.log(sum3(5, 10)),
|
|
|
+ intRandom: console.log(intRandom(2, 15)),
|
|
|
+ greetAll: greetAll("Superman"),
|
|
|
+ sum: console.log(sum(1)),
|
|
|
+ default: "Такого задания нет"
|
|
|
+}
|