// a
function a(msg) {
   return alert(msg)
}

// cube 
function cube(num) {
    return num**3
}

//avg2
function avg2(num1, num2) {
    return (num1 + num2) / 2
}

//sum3
function sum3(num1, num2, num3=0) {
    return num1 + num2 + num3
}

//intRandom
function intRandom(min, max) {
    let temp = min
    min = isNaN(max)? 0 : Math.ceil(min)
    max = Math.floor(max) || temp

    res = (Math.random() * (max - min) + min) <= 0? Math.ceil(Math.random() * (max - min) + min) : Math.floor(Math.random() * (max+1 - min) + min)
    return res === -0? 0 : res
}

//greetAll
function greetAll() {
    let greet = 'Hello '
    for(let i = 0; i < arguments.length; i++) {
        greet += i === arguments.length - 1? `${arguments[i]}` : `${arguments[i]}, `
    }
    return alert(greet)
}

//sum
function sum() {
    let sum = 0
    for(let i = 0; i < arguments.length; i++) {
        sum += arguments[i]
    }
    return sum
}

//Union
function aSample() {
    a('HELLO!')
}

function cubeSample() {
    return cube(5)
}

function avg2Sample() {
    return avg2(10, 5)
}

function sum3Sample() {
    return sum3(5,10,100500)
}

function intRandomSample() {
    return intRandom(15, 27)
}

function greetAllSample() {
    greetAll('Mihail', 'Bogdan', 'Denis')
}

function sumSample() {
    return sum(2, 3, 4, 5, 10)
}

let sample = prompt('Введите название задания','') || ''
switch (sample.toLowerCase()){
    case "a": 
        aSample()
        break;

    case "cube":
        console.log('cube: ',cubeSample())
        break;

    case "avg2":
        console.log('avg2: ',avg2Sample())
        break;

    case "sum3":
        console.log('sum3: ',sum3Sample())
        break;

    case "intrandom":
        console.log('intRandom: ',intRandomSample())
        break;

    case "greetall":
        greetAllSample()
        break;

    case "sum":
        console.log('sum: ',sumSample())
        break;

    default:
        alert('совпадений не найдено.')
        break;
}

let functionSamples = {
    a: aSample,
    cube: cubeSample,
    avg2: avg2Sample,
    sum3: sum3Sample,
    intrandom: intRandomSample,
    greetall: greetAll,
    sum: sumSample
}

alert('STARTING FROM OBJECT')
console.log('started from sample object:', functionSamples[sample]())
