// a('УУУУУУУУУУУ')
function a(text) {
   alert(text)
}

// console.log(cube(2))
function cube(number) {
   return number ** 3
}

// console.log(avg2(1,2))
function avg2(number1, number2) {
   return (number1 + number2) / 2
}

// console.log(sum3(10,5))
function sum3(num1 = 0, num2 = 0, num3 = 0) {
   return +num1 + +num2 + +num3
}

// console.log(intRandom(100))
function intRandom(bottom, top = 0) {
   let range = top - bottom
   let inputNum = Math.random()
   let output = Math.round((range * inputNum) + bottom)
   return output
}

// console.log(greetAll('AAAAA','UUUUUU','gUuuUuu'))
function greetAll() {
   let str = 'Hello '
   for (let i = 0; i < arguments.length; i++) {
      if (i < (arguments.length - 1)) {
         str += arguments[i]
         str += ', '
      } else {
         str += arguments[i]
      }
   }
   alert(str)
}

// console.log(sum(10,5,1,2,1,2,100))
function sum() {
   let num = 0
   for (let i = 0; i < arguments.length; i++) {
      num += +arguments[i]
   }
   return num
}

function aSample() {
   a("Привет!")
}  
function cubeSample() {
   console.log(cube(5))
}
function avg2Sample() {
   console.log(avg2(1,2))
   console.log(avg2(10,5))
}
function sum3Sample() {
   console.log(sum3(1,2,3))
   console.log(sum3(5,10,100500))
   console.log(sum3(5,10))
}
function intRandomSample() {
   console.log(intRandom(2,15))
   console.log(intRandom(-1,-1))
   console.log(intRandom(0,1))
   console.log(intRandom(10))
}
function greetAllSample() {
   greetAll("Superman")
   greetAll("Superman", "SpiderMan")
   greetAll("Superman", "SpiderMan", "Captain Obvious")
}
function sumSample() {
   console.log(sum(1))
   console.log(sum(2))
   console.log(sum(10,20,40,100))
}

// union()
function union() {  
   let chooser = prompt("Введите название задания")
   switch (chooser.toLowerCase()){
      case "a": aSample()
         break
      case "cube": cubeSample()
         break
      case "avg2": avg2Sample()
         break
      case "sum3": sum3Sample()
         break
      case "intrandom": intRandomSample()
         break
      case "greetall": greetAllSample()
         break
      case "sum": sumSample()
         break
   }
}

// unionDeclarative()
function unionDeclarative() {
   let chooser = prompt("Введите название задания")

   chooserFunc(chooser)
   function chooserFunc(sample) {
      const samples = {
         a: function () {
            return aSample()
         },
         cube: function () {
            return cubeSample()
         },
         avg2: () => avg2Sample(),
         sum3: () => sum3Sample(),
         intrandom: () => intRandomSample(),
         greetall: () => greetAllSample(),
         sum: () => sumSample(),
      }
      return samples[sample.toLowerCase()]?.() || console.log("sample not found")
   }
}