123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- // 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')]())
|