123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- //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: "Такого задания нет"
- }
|