|
@@ -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("Вася, Петя")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|