function a(message) {
    alert(message);
}

function cube(c) {
    return c ** 3;
}

// avg2
function avg2(x, y) {
    return ((x + y) / 2);
}

// sum3
function sum3(d, f, j) {
    d = d || 0;
    f = f || 0;
    j = j || 0;
    return (d + f + j);
}

//intRandom
function intRandom(min, max) {
    if (max === undefined) {
        result = (Math.round(Math.random() * min))
    } else
        result = (Math.round(Math.random() * (max - min) + min));
    return result;
}

// greetAll
function greetAll() {
    for (let name of arguments) {
        alert(`Привет ${name}`);
    }
}

// sum
function sum() {
    let numberSum = 0;
    for (let num of arguments) {
        numberSum = numberSum + num;
    }
    return numberSum;
}

function aSample() {
    a("Привет!");
}

function cubeSample() {
    let num = +prompt("Введите число");
    alert(cube(num));
}

function avg2Sample() {
    let a = +prompt("Введите первое число");
    let b = +prompt("Введите второе число");
    alert(avg2(a, b));
}

function sum3Sample() {
    alert(sum3(1, 2, 3));
    alert(sum3(5, 10, 100500));
    alert(sum3(5, 10));
}

function intRandomSample() {
    alert(intRandom(2, 15));
    alert(intRandom(-1, -1));
    alert(intRandom(0, 1));
    alert(intRandom(10));
}

function greetAllSample() {
    greetAll("Вася", "Петя", "Жора");
    greetAll("Вася", "Петя");
}

function sumSample() {
    alert(sum(5, 3, 8));
    alert(sum(2));
    alert(sum(10, 20, 40, 100));
}

var sample = prompt("Введите название задания");
switch (sample.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;
}

var sampleName = prompt("Введите название задания");
const arr = {
    "a": "aSample",
    "cube": "cubeSample",
    "avg2": "avg2Sample",
    "sum3": "sum3Sample",
    "intrandom": "intRandomSample",
    "greetall": "greetAllSample",
    "sum": "sumSample",
}
window[arr[sampleName]]();
