123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- // a
- function a(){
- alert("Hello")
- }
- a();
- // cube
- function cube(x){
- return x**3;
- }
-
- cube();
- // avg2
- function avg2(a,b){
- return (a + b)/2
- }
- avg2();
- // sum3
- function sum3(a,b,c){
- return (a + b + c) || (a + b)
- }
- sum3();
- // intRandom
- function intRandom(a,b) {
- if(b === undefined){
- c = (Math.round(Math.random() *a))
- }else
- c = (Math.round(Math.random() * (b - a) + a));
- return c
- }
- intRandom()
- // greetAll ???
- let guys = "";
- function greetAll(){
- for(i = 0;i<arguments.length;i++){
- guys+= " " + arguments[i]};
- alert(`Hi, ${guys}`)
- }
- greetAll()
- // sum
- function sum(){
- let result = 0;
- for(i = 0;i<arguments.length;i++){
- result += arguments[i]};
- return result
- }
- sum()
- // Union
- // function aSample(){
- // a()
- // };
- // function cubeSample(){
- // cube()
- // };
- // function avg2Sample(){
- // avg2()
- // };
- // function sum3Sample(){
- // sum3()
- // };
- // function randomSample(){
- // intRandom()
- // };
- // function greetSample(){
- // greetAll()
- // };
- // function sumSample(){
- // sum()
- // };
- let sample = prompt('Введите задание');
- switch(sample.toLowerCase()){
- case "a": a()
- break
- case "cube": cube(2)
- break
- case "avg2": avg2(3,4)
- break
- case "sum3": sum3(5,6,7)
- break
- case "intRandom": intRandom(8,12)
- break
- case "greetAll": greetAll("Oleg","Ivan")
- break
- case "sum": sum(9,10,11,13,14)
- break
- }
- // Union declarative
- let samplee = {
- "a": a(),
- "cube": cube(2),
- "avg2": avg2(3,4),
- "sum3": sum3(5,6,7),
- "intRandom": intRandom(8,12),
- "greetAll": greetAll('Oleg','Ivan'),
- "sum": sum(9,10,11,12,13)
- }
|