123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- // htmlTree()
- function htmlTree() {
- let body = {
- tagName: 'body',
- attrs: {},
- children: [
- { tagName: 'div',
- attrs: {},
- children: [
- { tagName: 'span',
- attrs: {},
- children: 'Enter a data please'
- },
- { tagName: 'br',
- attrs: {}
- },
- { tagName: 'input',
- attrs: {
- type: 'text',
- id: 'name'
- }
- },
- { tagName: 'input',
- attrs: {
- type: 'text',
- id: 'surname'
- }
- }
- ]
- },
- { tagName: 'div',
- attrs: {},
- children: [
- { tagName: 'button',
- attrs: {
- id: 'ok'
- },
- children: 'OK'
- },
- { tagName: 'button',
- attrs: {
- id: 'cansel'
- },
- children: 'Cancel'
- }
- ]
- }
- ]
- }
- console.log(body.children[1].children[1].children)
- console.log(body.children[0].children[3].attrs.id)
- }
- // declarativeFields()
- function declarativeFields() {
- var notebook = {
- brand: prompt("Enter a brand",""),
- type: prompt("Enter a type",""),
- model: prompt("Enter a model",""),
- ram: +prompt("Enter amount of ram (gb)",""),
- size: prompt("Enter a size of screen (inch)",""),
- weight: +prompt("Enter a weight (kg)",""),
- resolution: {
- width: +prompt("Enter a resolution width (px)",""),
- height: +prompt("Enter a resolution height (px)",""),
- },
- };
- console.log(notebook);
-
- var phone = {
- brand: prompt("Enter a brand",""),
- model: prompt("Enter a model",""),
- ram: +prompt("Enter amount of ram (gb)",""),
- color: prompt("Enter a color",""),
- };
- console.log(phone);
-
- var person = {
- name: prompt("Enter a name",""),
- surname: prompt("Enter a surname",""),
- married: confirm("Is person married?",""),
- }
- console.log(person);
- }
- // tableMult()
- function tableMult() {
- let str = '<table>'
- for (let rowIndex=1; rowIndex<10; rowIndex++) {
- str += '<tr>'
- for (let j=1; j<10; j++) {
- str += `<td>${rowIndex*j}</td>`
- }
- str += '</tr>'
- }
- str += '</table>'
- document.write(str)
- }
- // contArr()
- function contArr() {
- let inputArr = [1,2,3,4,5,6,'qqq',true]
- let newElement = 0
- for (let i=0; i<inputArr.length; i++) {
- newElement += inputArr[i]
- }
- inputArr.push(newElement)
- console.log(inputArr)
- }
- // tableMultObj()
- function tableMultObj() {
- let phone = {
- brand: "meizu",
- model: "m2",
- ram: 2,
- color: "black",
- uuuuu: true
- }
- let str = '<table>\n'
- for (const [key, value] of Object.entries(phone)) {
- str += ` \n<tr><td><b>${key}</b></td><td>${value}</td></tr>\n`
- }
- str += '</table>'
- document.write(str)
- }
- // objectLinks()
- function objectLinks() {
- var notebook = {
- brand: "HP",
- type: "440 G4",
- model: "Y7Z75EA",
- ram: 4,
- size: "14",
- weight: 1.8,
- resolution: {
- width: 1920,
- height: 1080,
- },
- };
-
- var phone = {
- brand: "meizu",
- model: "m2",
- ram: 2,
- color: "black",
- };
-
- var person = {
- name: "Donald",
- surname: "Trump",
- married: true,
- };
- person.smartphone = phone;
- person.laptop = notebook;
- phone.owner = person;
- notebook.owner = person;
- console.log(person.smartphone.owner.laptop.owner.smartphone == person.smartphone);
- }
- // imperativeArrayFill3()
- function imperativeArrayFill3() {
- let arr = [];
- arr[0] = prompt("Вводи элемент массива","")
- arr[1] = prompt("Вводи элемент массива","")
- arr[2] = prompt("Вводи элемент массива","")
- console.log(arr);
- }
- // whileConfirm()
- function whileConfirm() {
- let a = true;
- while (a) {
- a = confirm('Продолжить цикл?')
- }
- }
- // arrayFill()
- function arrayFill() {
- let arr = [];
- let res = null;
- do {
- res = prompt("Вводи элемент массива","");
- if (res !== null) {
- arr.push(res);
- }
- } while (res !== null)
- console.log(arr);
- }
- // arrayFillNopush()
- function arrayFillNopush() {
- let arr = [];
- let res = null;
- let i = 0;
- do {
- res = prompt("Вводи элемент массива","");
- if (res !== null) {
- arr[i] = res;
- }
- i++;
- } while (res !== null)
- console.log(arr);
- }
- // infiniteProbability()
- function infiniteProbability() {
- let i = 0;
- while (true) {
- if (Math.random() > 0.9) {
- break;
- }
- i++;
- }
- console.log(`Количество итераций: ${i}`);
- }
- // emptyLoop()
- function emptyLoop() {
- for (let i = 0; i !== null; i = prompt("Продолжить цикл?","")) {}
- }
- // progressionSum()
- function progressionSum() {
- let n = Number(prompt("До какого числа продолжать прогрессию?",""));
- let sum = 0;
- for (let i = 1; i <= n; i += 3) {
- sum += i;
- }
- console.log(sum);
- }
- // chessOneLine()
- function chessOneLine() {
- let size = +prompt("Введите длинну строки","");
- let str = '';
- for (let i = 0; i < size; i++) {
- if (i % 2 === 0) {
- str += ' ';
- } else {
- str += '#';
- }
- }
- console.log(str);
- }
- // numbers()
- function numbers() {
- let str = ''
- for (let i=0; i < 10; i++) {
- for (let j=0; j < 10; j++) {
- str += `${j}`
- }
- str += '\n'
- }
- console.log(str)
- }
- // chess()
- function chess() {
- let size = +prompt("Введите размер поля","")
- let str = ''
- let counter = 0
- while (counter < size) {
- counter++
- if (counter % 2 === 0) {
- for (let counter2 = 0; counter2 < size; counter2++) {
- if (counter2 % 2 === 0) {
- str += '.'
- } else {
- str += '#'
- }
- }
- str += '\n'
- } else {
- for (let counter3 = 0; counter3 < size; counter3++) {
- if (counter3 % 2 === 0) {
- str += '#'
- } else {
- str += '.'
- }
- }
- str += '\n'
- }
- }
- console.log(str)
- }
- // cubes()
- function cubes() {
- let arr = []
- let inputNumber = +prompt("Введите длинну массива","")
- let i = 0
- while (i < inputNumber) {
- let element = (i ** 3)
- arr.push(element)
- i++
- }
- console.log(arr)
- }
- // multiplyTable()
- function multiplyTable() {
- let arr = []
- for (let i=0; i < 10; i++) {
- arr[i] = []
- for (let j=0; j < 10; j++) {
- arr[i].push(i*j)
- }
- }
- console.log(arr)
- return arr
- }
- // matrixToHtmlTable()
- function matrixToHtmlTable() {
- let inputArr = multiplyTable()
- let str = '<table>'
- for (let i = 0; i < inputArr.length; i++) {
- str += '<tr>'
- for (let j = 0; j < inputArr[i].length; j++) {
- str += `<td>${inputArr[i][j]}</td>`
- }
- str += '</tr>'
- }
- str += '</table>'
- document.write(str)
- }
- // triangle()
- function triangle() {
- let height = +prompt("Введите высоту треугольника","")
- let width = (height * 2 - 1)
- let arr = []
- let str = ''
- for (let colCounter = 0; colCounter < width; colCounter++) {
- arr[colCounter] = []
- for (rowCounter = 0; rowCounter < height; rowCounter++) {
- if (colCounter < height) {
- if (rowCounter <= colCounter) {
- arr[colCounter].push('#')
- } else {
- arr[colCounter].push('.')
- }
- } else {
- if (rowCounter < (width - colCounter)) {
- arr[colCounter].push('#')
- } else {
- arr[colCounter].push('.')
- }
- }
- }
- }
- // console.log(arr)
- for (let j = 1; j <= arr[0].length; j++) {
- for (let i = 0; i < arr.length; i++) {
- str += `${arr[i][arr[i].length - j]}`
- }
- str += '\n'
- }
- console.log(str)
- }
- // fortuneTeller()
- function fortuneTeller() {
- let history = [1,1,1,1]
- let predictArray = [[[[],[]],[[],[]]],[[[],[]],[[],[]]]]
- let loop = true;
- while (loop) {
- let compOutput = null
- if (predictArray[history[0]][history[1]][history[2]][history[3]] || predictArray[history[0]][history[1]][history[2]][history[3]] === 0) {
- compOutput = predictArray[history[0]][history[1]][history[2]][history[3]]
- console.log(compOutput)
- } else {
- compOutput = Math.floor(Math.random()*2)
- console.log(compOutput)
- }
- let userInput = +confirm('Нажмите ОК, если выбираете 1\nНажмите Отмена, если выбираете 0')
- // console.log(userInput)
- predictArray[history[0]][history[1]][history[2]][history[3]] = userInput
- // console.log(predictArray)
- history.push(userInput)
- history.shift()
- // console.log(history)
- loop = confirm('Еще?')
- }
- }
|