1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- // a
- function a() {
- alert('Привет');
- }
- a()
- // cube
- function cube() {
- console.log(prompt('number') ** 3);
- }
- cube()
- // avg2
- function avg2(a, b) {
- console.log((a + b) / 2);
- }
- avg2(5, 10)
- avg2(1, 2)
- // sum3
- function sum3(a, b, c) {
- a = a || 0;
- b = b || 0;
- c = c || 0;
- return a + b + c;
- }
- console.log(sum3(1, 2, 3))
- console.log(sum3(5, 10, 100500))
- console.log(sum3(5, 10))
- // intRandom
- function intRandom(min, max) {
- min = min || 0;
- max = max || 0;
- let result = Math.random() * (max - min) + min;
- return Math.round(result)
- }
- console.log(intRandom(2, 15))
- console.log(intRandom(-1, -1))
- console.log(intRandom(0, 1))
- console.log(intRandom(10))
- // greetAll
- function greetAll(...arguments) {
- for (let arg of arguments) {
- alert(`Hello ${arg}!`)
- }
- }
- greetAll("Superman")
- greetAll("Superman", "SpiderMan")
- greetAll("Superman", "SpiderMan", "Captain Obvious")
- // sum
- function sum(...arguments) {
- let result = 0
- for (let arg of arguments) {
- result += arg
- }
- console.log(result)
- }
- sum(1)
- sum(2)
- sum(10, 20, 40, 100)
- // Union
- var sample = prompt("Введите название задания")
- switch (sample.toLowerCase()) {
- case "a": a()
- break;
- case "cube": cube()
- break;
- case "avg2": avg2()
- break;
- case "sum3": sum3()
- break;
- case "intRandom": intRandom()
- break;
- case "greetAll": greetAll()
- break;
- case "sum": sum()
- break;
- }
- // Union declarative
- var sample = prompt("Введите название задания").toLowerCase()
- var sample2;
- var sample1 = {
- a: a(),
- cube: cube(),
- avg2: avg2(),
- sum3: sum3(),
- intRandom: intRandom(),
- greetAll: greetAll(),
- sum: sum(),
- }
- sample2 = sample[`${sample}`]
|