Загрузка данных


const student = {
    name: "ИМЯ",
    age: 25,
    stud_num: 5,
    last_vis: new Date()
}

const computer = {
    comp_num: student.stud_num,
    stud_name: student.name,
    is_working: true
}


 const classRoom = {
    students: [],
    computers: [], 
    className: 406,
 }

    // quantityOfStudents (students) {
    //        let j = this.students
    //     for (let i=0; i < j.length; i ++) {

    //     } 
    // }
    // seats: this.computers.length > 0 ? this.computers.length : 25
    // city: Moscow,
    // greet () {
    //     console.log(`Знач-е объ-та student:
    //         ${this.name},
    //         ${this.age},
    //         ${this.city}`),   
    // },
    // newObject: {
    //     array: [1, 2, 3, 4]
    // }
 
classRoom.seats = classRoom.computers.length > 0 // if
    ? classRoom.computers.length  // then
    : 25; //else

function generateLastVisit () {
    const date = new Date ()
    const randomNumber = Math.floor(Math.random() * 10 ) + 1;
    date. setDate(date.getDate() - randomNumber)

    return date;
}

function initClassData (currentClassRoom) {
    let isFull = false; 
    let countOfComputers = currentClassRoom.seats;
    
    while (!isFull) {
        const student = new Object();
        student.name = "student - " + countOfComputers
        student.age = countOfComputers % 2 == 0 ? countOfComputers * 2 : countOfComputers * 1.8
        student.stud_num = countOfComputers
        student.last_vis = generateLastVisit ();

        const computer = new Object();
        computer.comp_num = countOfComputers;
        computer.is_working = countOfComputers % 2 == 0 ? true : false;
        computer.stud_name = student.name;

        if (countOfComputers < 1) {
            isFull = true
        } else {
            currentClassRoom.students.push(student)
            currentClassRoom.computers.push(computer)
            countOfComputers--
        }
    }
}

initClassData(classRoom)
console.log(classRoom);