// a function a() { return alert('Привет'); } a() // cube function cube() { return console.log(prompt('number') ** 3); } cube() // avg2 function avg2() { let a = +prompt('num1') let b = +prompt('num2') return console.log((a + b) / 2); } avg2() // avg2(5, 10) // avg2(1, 2) // sum3 function sum3(a, b, c) { a = a || 0; b = b || 0; c = c || 0; a = +prompt('num1') b = +prompt('num2') c = +prompt('num3') return console.log(a + b + c); } sum3() // 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) // } function intRandom() { let min = +prompt('min'); let max = +prompt('max'); if (max === undefined) { max = min min = 0 } return console.log(Math.floor(Math.random() * (max - min + 1) + min)) } intRandom() // console.log(intRandom(2, 15)) // console.log(intRandom(-1, -1)) // console.log(intRandom(0, 1)) // console.log(intRandom(10)) // greetAll function greetAll(...arguments) { alert(`Hello ${arguments}!`) } 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("Введите название задания").toLowerCase() switch (sample) { 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 = { a() { a() }, cube() { cube() }, avg2() { avg2() }, sum3() { sum3() }, intrandom() { intRandom() }, greetall() { greetAll("Superman", "SpiderMan", "Captain Obvious") }, sum() { sum(10, 20, 40, 100) } } console.log(sample[prompt('enter')]())