123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- // 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
- function greetAll(){
- let guys = "";
- for(i = 0;i<arguments.length;i++){
- guys+= "," + " " + arguments[i]};
- alert(`Hi ${guys}`)
- }
- // sum
- function sum(){
- let result = 0;
- for(i = 0;i<arguments.length;i++){
- result += arguments[i]};
- return result
- }
- sum()
- // Union
- function aSample(){
- return a()
- };
- function cubeSample(){
- return cube(2)
- };
- function avg2Sample(){
- return avg2(3,4)
- };
- function sum3Sample(){
- return sum3(5,6,7)
- };
- function randomSample(){
- return intRandom(8,12)
- };
- function greetSample(){
- return greetAll("Oleg","Jopa")
- };
- function sumSample(){
- return sum(9,10,11,12,13)
- };
- let sample = prompt('Введите задание');
- switch(sample.toLowerCase()){
- case "a": aSample()
- break
- case "cube": cubeSample()
- break
- case "avg2": avg2Sample()
- break
- case "sum3": sum3Sample()
- break
- case "intRandom": randomSample()
- break
- case "greetAll": greetSample()
- break
- case "sum": sumSample()
- break
- }
- // Union declarative ?
- let samplee = {
- "a": aSample(),
- "cube": cubeSample(),
- "avg2": avg2Sample(),
- "sum3": sum3Sample(),
- "intRandom": randomSample(),
- "greetAll": greetSample(),
- "sum": sumSample()
- }
- let qvest = prompt('Какая функция?')
- alert(samplee[qvestion])
|