<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Home_Task #5. Prokhorova Anna</title>
</head>
<body>
    <script>
        // 1. Создать объект Point, содержащий два свойства: "x" и "y" — координаты точки, и метод GetQuadrant, вычисляющий,
        // в каком квадранте в декартовой системе координат находится данная точка.
        // Протестируйте данный объект, изменяя значения его координат, и повторно вызавая метод GetQuadrant.
            a = +prompt("Enter coordinates (x):");
            b = +prompt("Enter coordinates (y):");
            if (isNaN(a) || isNaN(b)) {
                console.log("It isn't number!");
            }

            var point = {x: a, y: b};

            var GetQuadrant = function(x, y) {
                if (point.x > 0 && point.y > 0) {
                    console.log("Point in the first quadrant");
                }
                else if (point.x > 0 && point.y < 0) {
                    console.log("Point in the second quadrant");
                }
                else if (point.x < 0 && point.y < 0) {
                    console.log("Point in the third quadrant");
                } 
                else if (point.x < 0 && point.y > 0 ) {
                    console.log("Point in the fourth quadrant");
                }
                else if (point.x == 0 && point.y == 0) {
                    console.log("This is origin");
                }
            }
            GetQuadrant();

    </script>

    <script>
        // 2. Создать объект Calculator, который должен содержать методы для расчета суммы, разности, произведения и частного двух чисел.
        // Протестировать данный объект, принимая от пользователя значения двух операндов и знак операции.
        // В зависимости от принятого знака операции, вызвать соответствующий метод.
        var calculator = {
            sum: function (a, b) {
                var result = a + b;
                console.log(result);
            },
            sub: function (a, b) {
                var result = a - b;
                console.log(result);
            },
            mul: function (a, b) {
                var result = a * b;
                console.log(result);
            },
            div: function (a, b) {
                var result = a / b;
                console.log(result);
            },
        }

        var a = +prompt("Input first operand:");
        var sign = prompt("Input sign:");
        var b = +prompt("Input second operand:");
        if (isNaN(a) || isNaN(b)) {
            console.log("One of arguments is not a number!");
            }

        if (sign == "+") {
            calculator.sum(a, b);
        } else if (sign == "-") {
            calculator.sub(a, b);
        } else if (sign == "*") {
            calculator.mul(a, b);
        } else if (sign == "/") {
            calculator.div(a, b);
        } else {
            console.log("Unsupported operation!");
        }

    </script>

    <script>
        // 3. Создать массив, который будет хранить в себе информацию о сотрудниках предприятия. Каждый элемент масива — объект,
        // содержащий свойства: name, sName, age, occupation, и метод show, который выводит всю информацию о пользователе.
        // Реализовать заполнение массива пользователем. По окончанию заполнения — вывести информацию о сотрудниках.
      
        var company = [
            p1 = {
                name: a = prompt("Enter first name:"), 
                sName: b = prompt("Enter surname:"),
                age: c = prompt("Enter age:"),
                occupation: d = prompt("Enter occupation:"),
                show: function() {
                    console.log("First name: " + this.name);
                    console.log("Surname: " + this.sName);
                    console.log("Age: " + this.age + " years old");
                    console.log("Occupation: " + this.occupation);
                }
            },
            p2 = {
                name: a = prompt("Enter first name:"), 
                sName: b = prompt("Enter surname:"),
                age: c = prompt("Enter age:"),
                occupation: d = prompt("Enter occupation:"),
                show: function() {
                    console.log("First name: " + this.name);
                    console.log("Surname: " + this.sName);
                    console.log("Age: " + this.age + " years old");
                    console.log("Occupation: " + this.occupation);
                }
            },
            p3 = {
                name: a = prompt("Enter first name:"), 
                sName: b = prompt("Enter surname:"),
                age: c = prompt("Enter age:"),
                occupation: d = prompt("Enter occupation:"),
                show: function() {
                    console.log("First name: " + this.name);
                    console.log("Surname: " + this.sName);
                    console.log("Age: " + this.age + " years old");
                    console.log("Occupation: " + this.occupation);
                }
            }
        ]
        
        for (var i = 0; i < company.length; i++) {
            company[i].show();
        }
       
    </script>

    <script>
        // 4. Для предыдущего задания создайте функцию, которая будет принимать в себя массив объектов-сотрудников, и каждому из объектов
        // будет добавлять новое свойство "salary", хранящее зарплату сотрудника. 
        // Зарплата расчитывается, исходя из значения свойства "occupation" следующим образом:
        //   • "director" — 3000;
        //   • "manager" — 1500;
        //   • "programmer" — 2000;
        //   • для остальных значений — 1000.
        // После выполнения функции — вывести информацию о сотрудниках.
        var company = [
            p1 = {
                name: a = prompt("Enter first name:"), 
                sName: b = prompt("Enter surname:"),
                age: c = prompt("Enter age:"),
                occupation: d = prompt("Enter occupation:"),
            },
            p2 = {
                name: a = prompt("Enter first name:"), 
                sName: b = prompt("Enter surname:"),
                age: c = prompt("Enter age:"),
                occupation: d = prompt("Enter occupation:"),
            },
            p3 = {
                name: a = prompt("Enter first name:"), 
                sName: b = prompt("Enter surname:"),
                age: c = prompt("Enter age:"),
                occupation: d = prompt("Enter occupation:"),
            }
        ]

        function assignSalary(arr) {
            for (var i = 0; i < arr.length; i++) {
                switch (arr[i].occupation) {
                    case "director":
                        arr[i].salary = 3000;
                        break;
                    case "manager":
                        arr[i].salary = 1500;
                        break;
                    case "programmer":
                        arr[i].salary = 2000;
                        break;
                    default:
                        arr[i].salary = 1000;
                }
            }
        }

        assignSalary(company);

        for (var i = 0; i < company.length; i++) {
            console.log("First name: " + company[i].name);
            console.log("Surname: " + company[i].sName);
            console.log("Age: " + company[i].age + " years old");
            console.log("Occupation: " + company[i].occupation);
            console.log("Salary: " + company[i].salary);
        }

    </script>

    <script>
        // 5. Для задания 3 создать метод, позволяющий отсортировать массив сотрудников по одному из свойств: name, sName, age, occupation, salary.
        // Параметр для сортировки принимается от пользователя.
        // После выполнения функции — вывести информацию о сотрудниках.
        var company = [
            p1 = {
                name: a = prompt("Enter first name:"), 
                sName: b = prompt("Enter surname:"),
                age: c = +prompt("Enter age:"),
                occupation: d = prompt("Enter occupation:"),
            },
            p2 = {
                name: a = prompt("Enter first name:"), 
                sName: b = prompt("Enter surname:"),
                age: c = +prompt("Enter age:"),
                occupation: d = prompt("Enter occupation:"),
            },
            p3 = {
                name: a = prompt("Enter first name:"), 
                sName: b = prompt("Enter surname:"),
                age: c = +prompt("Enter age:"),
                occupation: d = prompt("Enter occupation:"),
            }
        ]

        function assignSalary(arr) {
            for (var i = 0; i < arr.length; i++) {
                switch (arr[i].occupation) {
                    case "director":
                        arr[i].salary = 3000;
                        break;
                    case "manager":
                        arr[i].salary = 1500;
                        break;
                    case "programmer":
                        arr[i].salary = 2000;
                        break;
                    default:
                        arr[i].salary = 1000;
                }
            }
        }

        assignSalary(company);

        var crit = prompt("Enter criteria (name, sName, age, salary): ");
        company.sort(function(a, b) {
            switch (crit) {
                case "name":
                    if (a["name"] > b["name"]) {
                        return 1;
                    }
                    else if (a["name"] < b["name"]) {
                        return -1;
                    } else {return 0;}
                    break;
                case "sName":
                    if (a["sName"] > b["sName"]) {
                        return 1;
                    }
                    else if (a["sName"] < b["sName"]) {
                        return -1;
                    } else {return 0;}
                    break;
                case "age":
                    return a["age"] - b["age"];
                    break;
                case "salary":
                    return a["salary"] - b["salary"];
                    break;
                default:
                    alert("None");
            }
        })

    </script>
    
</body>
</html>