function htmlTree() {
    let body = {
        tagName: 'body',
        attrs: {},
        subTags:[
            {
                tagName: 'div',
                attrs: {},
                subTags:[
                    {
                        tagName: 'span',
                        attrs: {},
                        subTags: 'Enter a data please:'
                    },
                    {
                        tagName: 'br'
                    },
                    {
                        tagName: 'input',
                        attrs: {
                            type: 'text',
                            id: 'name'
                        },
                        subTags:[]
                    },
                    {
                        tagName: 'input',
                        attrs: {
                            type: 'text',
                            id: 'surname'
                        },
                        subTags:[]
                    }
                ]
            },
            {
                tagName: 'div',
                attrs: {},
                subTags:[
                    {
                        tagName: 'button',
                        attrs: {
                            id: 'ok'
                        },
                        subTags: 'OK'
                    },
                    {
                        tagName: 'button',
                        attrs: {
                            id: 'cancel'
                        },
                        subTags: 'Cancel'
                    }
                ]
            }
        ]
    }
    console.log(body.subTags[1].subTags[1].subTags);
    console.log(body.subTags[0].subTags[3].attrs.id);
} // html tree
function declarativeFields() {
    let notebook = {
        brand: prompt("Enter a brand"),
        type:  prompt("Enter a type"),
        model: prompt("Enter a model"),
        ram: +prompt("Enter a ram"),
        size: prompt("Enter a size"),
        weight: +prompt("Enter a weight"),
        resolution: {
            width: +prompt("Enter a width"),
            height: +prompt("Enter a height"),
        },
    };

    let phone = {
        brand: prompt("Enter a brand"),
        model: prompt("Enter a model"),
        ram: +prompt("Enter a ram"),
        color: prompt("Enter a color")
    };

    let person = {
        name: prompt("Enter a name"),
        surname: prompt("Enter a surname"),
        married: Boolean(confirm("Married?"))
    }
} // declarative fields
function objectLinks() {
    let notebook = {
        brand: prompt("Enter a brand"),
        type:  prompt("Enter a type"),
        model: prompt("Enter a model"),
        ram: +prompt("Enter a ram"),
        size: prompt("Enter a size"),
        weight: +prompt("Enter a weight"),
        resolution: {
            width: +prompt("Enter a width"),
            height: +prompt("Enter a height"),
        },
        owner: person
    };

    let phone = {
        brand: prompt("Enter a brand"),
        model: prompt("Enter a model"),
        ram: +prompt("Enter a ram"),
        color: prompt("Enter a color"),
        owner: person
    };

    let person = {
        name: prompt("Enter a name"),
        surname: prompt("Enter a surname"),
        married: Boolean(confirm("Married?")),
        smartphone: phone,
        laptop: notebook
    }
} // object links
function imperativeArrayFill3() {
    let arr = [];
    arr[arr.length] = prompt('Введите данные');
    arr[arr.length] = prompt('Введите данные');
    arr[arr.length] = prompt('Введите данные');
    alert(arr)
} // imperative array fill 3
function whileConfirm() {
   while (true){
       if (confirm('Продолжаем?')) break;
   }
   //while(!confirm());
} // while confirm
function arrayFill() {
    let flag = false;
    let arr = [];
    while (flag === false){
        arr.push(prompt('Введите елемент'));
        if (arr[arr.length-1] === null){
            arr.pop();
            flag = true;
        }
    }
} // array fill
function arrayFillNoPush() {
    let flag = false;
    let arr = [];
    for (let i = 0; flag === false; i++) {
        arr[i] = prompt('Введите елемент');
        if (arr[arr.length-1] === null) {
            arr.pop();
            flag = true;
        }
    }
} // array fill nopush
function infiniteProbability() {
    let i = 0;
    while (true) {
        i++;
        if (Math.random() > 0.9){
            alert(i);
            break;
        }
    }
} // infinite probability
function emptyLoop() {
    while(!prompt('Значение', '0'));
} // empty loop
function progressionSum(N = 20) {
    let sum = 0;
    for (let i = 1; i < N; i += 3) {
        sum += i;
    }
    alert(sum);
} // progression sum
function chessOneLine(value = 5) {
    let str = '';
    for (let i = 0; i < value; i++) {
        str += ' #';
    }
    alert(str + ' ');
} // chess one line
function numbers() {
    let str = '';
    for (let i = 0; i < 10; i++){
        for (let j = 0; j < 10; j++){
            str += j;
        }
        str += '\n';
    }
    alert(str);
} // numbers
function chess(sizeX = 12, sizeY = 10) {
    let str = '';
    for (let i = 0; i < sizeY; i++) {
        for (let j = 0; j < sizeX/2; j++) {
            str.length === 0 ? str += '.#' : (str[str.length-2] === '.') ? str += '.#' : str += '#.';
        }
        str += '\n';
    }
    alert(str);
} // chess
function cubes(N = 10) {
    let arr = [];
    for (let i = 0; i < N; i++){
        arr.push(Math.pow(i,3));
    }
    alert(arr);
} // cubes
function multiplyTable() {
    let tableMulti = [];
    for (let i = 1; i <= 10; i++) {
        tableMulti[i] = [];
        for (let j = 1; j <= 10; j++) {
            tableMulti[i][j-1] = i * j;
        }
    }
    console.log(tableMulti);
} // multiply table
function matrixToHtmlTable() {
    let str = '<table>';
    let tableMulti = [];
    for (let i = 1; i <= 10; i++) {
        tableMulti[i] = [];
        for (let j = 1; j <= 10; j++) {
            tableMulti[i][j-1] = i * j;
        }
    }
    for (let row = 1; row <= tableMulti.length-1; row++) {
        str += '<tr>';
        for (let col = 0; col < tableMulti.length-1; col++) {
            str += `<td>${tableMulti[row][col]}</td>`;
        }
        str += '</tr>';
    }
    str += '</table>';
    document.querySelector('body').innerHTML = str;
} // matrix to html table
function blueBeltChallengeTheTriangle(sizeX = 11, sizeY = 6) {
    let defaultStr = [];
    let resultStr = '';
    if (sizeX % 2 === 0) sizeX++;
    for (let s = 0; s < sizeX; s++){
        defaultStr.push('.');
    }
    for (let i = 0; i < sizeY; i++) {
        for (let j = 0; j < 1; j += 3) {
            if (i <= 0){
                defaultStr[Math.floor(sizeX / 2)] = '#';
                resultStr += defaultStr.join('');
            }
            else {
                defaultStr[defaultStr.indexOf('#') - 1] = '#';
                defaultStr[defaultStr.lastIndexOf('#') + 1] = '#';
                resultStr += defaultStr.join('');
            }
        }
        resultStr += '\n';
    }
    console.log(resultStr);
} // Задание на синий пояс: Треугольник
function BlackBeltChallengeTheElectronicFortuneTeller () {
    let history = [1, 1, 1, 1];
    let predictArray = [[[[],[]],[[],[]]],[[[],[]],[[],[]]]];
    let userValue = 0;

    for (let i = 0; true; i++){
        if (i === 0){
            console.log(Math.round(Math.random()));
            userValue = +prompt('Введите число от 0 до 1', '0');
            if (userValue < 0 || userValue > 1 || isNaN(userValue)){
                alert('Вы ввели не верное значение');
                continue;
            }
            predictArray[history[0]][history[1]][history[2]][history[3]] = userValue;
            history.push(userValue);
            history.shift();
        }
        else {
            console.log(predictArray[history[0]][history[1]][history[2]][history[3]]);
            userValue = +prompt('Введите число от 0 до 1', '0');
            if (userValue < 0 || userValue > 1 || isNaN(userValue)){
                alert('Вы ввели не верное значение');
                continue;
            }
            predictArray[history[0]][history[1]][history[2]][history[3]] = userValue;
            history.push(userValue);
            history.shift();
        }
    }
} //Задание на черный пояс: Электронная гадалка