123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647 |
- {
-
- }
- {
- const flover = {
- type: 'palm',
- height: 150,
- color: 'green'
- }
- const dog = {
- type: 'york',
- sex: 'female',
- color: 'red'
- }
- const wife = {
- type: 'creator',
- sex: 'female',
- height: 165
- }
- }
- {
- const flover = {
- type: 'palm',
- height: 150,
- color: 'green',
- [prompt('Введите первый параметр для объекта "Цветок"')]: prompt('Введите описание этого параметра'),
- [prompt('Введите второй параметр для объекта "Цветок"')]: prompt('Введите описание этого параметра')
- }
- const dog = {
- type: 'york',
- sex: 'female',
- color: 'red',
- [prompt('Введите первый параметр для объекта "Собака"')]: prompt('Введите описание этого параметра'),
- [prompt('Введите второй параметр для объекта "Собака"')]: prompt('Введите описание этого параметра')
- }
- const wife = {
- type: 'creator',
- sex: 'female',
- height: 165,
- [prompt('Введите первый параметр для объекта "Жена"')]: prompt('Введите описание этого параметра'),
- [prompt('Введите второй параметр для объекта "Жена"')]: prompt('Введите описание этого параметра')
- }
- }
- {
- const flover = {
- type: 'palm',
- height: 150,
- color: 'green'
- }
- const dog = {
- type: 'york',
- sex: 'female',
- color: 'red'
- }
- const wife = {
- type: 'creator',
- sex: 'female',
- height: 165
- }
- const newObj = { ...flover }
- newObj[prompt('Введите имя ключа в поле ниже')] = prompt('Введите значение для указанного ранее ключа')
- console.log(newObj)
- }
- {
- const dataInput = {
- tagName: 'body',
- children: [
- {
- tagName: 'div',
- children: [
- {
- tagName: 'span',
- children: ['Enter a data please:']
- },
- {
- tagName: 'br'
- },
- {
- tagName: 'input',
- attrs: {
- type: 'text',
- id: 'name'
- }
- },
- {
- tagName: 'input',
- attrs: {
- type: 'text',
- id: 'surname'
- }
- }
- ]
- },
- {
- tagName: 'div',
- children: [
- {
- tagName: 'button',
- attrs: {
- id: 'ok'
- },
- children: ['OK']
- },
- {
- tagName: 'button',
- attrs: {
- id: 'cancel'
- },
- children: ['Cancel']
- }
- ]
- }
- ]
- }
- console.log(dataInput.children[1].children[1].children[0])
- console.log(dataInput.children[0].children[3].attrs.id)
- }
- {
- const dataInput = {
- tagName: 'body',
- children: [
- {
- tagName: 'div',
- children: [
- {
- tagName: 'span',
- children: ['Enter a data please:']
- },
- {
- tagName: 'br'
- },
- {
- tagName: 'input',
- attrs: {
- type: 'text',
- id: 'name'
- }
- },
- {
- tagName: 'input',
- attrs: {
- type: 'text',
- id: 'surname'
- }
- }
- ]
- },
- {
- tagName: 'div',
- children: [
- {
- tagName: 'button',
- attrs: {
- id: 'ok'
- },
- children: ['OK']
- },
- {
- tagName: 'button',
- attrs: {
- id: 'cancel'
- },
- children: ['Cancel']
- }
- ]
- }
- ]
- }
- dataInput.children[0].father = dataInput
- dataInput.children[1].father = dataInput
- dataInput.children[0].children[0].father = dataInput.children[0]
- dataInput.children[0].children[1].father = dataInput.children[0]
- dataInput.children[0].children[2].father = dataInput.children[0]
- dataInput.children[0].children[3].father = dataInput.children[0]
- dataInput.children[1].children[0].father = dataInput.children[1]
- dataInput.children[1].children[1].father = dataInput.children[1]
- }
- {
- const dataInput = {
- tagName: 'body',
- children: [
- {
- tagName: 'div',
- children: [
- {
- tagName: 'span',
- children: ['Enter a data please:']
- },
- {
- tagName: 'br'
- },
- {
- tagName: 'input',
- attrs: {
- type: 'text',
- id: 'name'
- }
- },
- {
- tagName: 'input',
- attrs: {
- type: 'text',
- id: 'surname'
- }
- }
- ]
- },
- {
- tagName: 'div',
- children: [
- {
- tagName: 'button',
- attrs: {
- id: 'ok'
- },
- children: ['OK']
- },
- {
- tagName: 'button',
- attrs: {
- id: 'cancel'
- },
- children: ['Cancel']
- }
- ]
- }
- ]
- }
- dataInput.children[1].children[0].attrs[prompt('ВВедите любой атрибут для тега "button"')] = prompt('Введите значение для этого атрибута')
- console.log(dataInput.children[1].children[0].attrs)
- }
- {
- const dataInput = {
- tagName: 'body',
- children: [
- {
- tagName: 'div',
- children: [
- {
- tagName: 'span',
- children: ['Enter a data please:']
- },
- {
- tagName: 'br'
- },
- {
- tagName: 'input',
- attrs: {
- type: 'text',
- id: 'name'
- }
- },
- {
- tagName: 'input',
- attrs: {
- type: 'text',
- id: 'surname'
- }
- }
- ]
- },
- {
- tagName: 'div',
- children: [
- {
- tagName: 'button',
- attrs: {
- id: 'ok'
- },
- children: ['OK']
- },
- {
- tagName: 'button',
- attrs: {
- id: 'cancel'
- },
- children: ['Cancel']
- }
- ]
- }
- ]
- }
- const { children: [{ children: [{ children: [span] }] }] } = dataInput
- console.log(span)
- const { children: [, { children: [, { children: [button] }] }] } = dataInput
- console.log(button)
- const { children: [{ children: [, , , { attrs: { id } }] }] } = dataInput
- console.log(id)
- }
- {
- let arr = [1, 2, 3, 4, 5, "a", "b", "c"]
- const [odd1, even1, odd2, even2, odd3, ...letters] = arr
- console.log(even1, even2, odd1, odd2, odd3, letters)
- }
- {
- let arr = [1, "abc"]
- const [number, [s1, s2, s3]] = arr
- console.log(number, s1, s2, s3)
- }
- {
- let obj = {
- name: 'Ivan',
- surname: 'Petrov',
- children: [{ name: 'Maria' }, { name: 'Nikolay' }]
- }
- const { children: [{ name: name1 }, { name: name2 }] } = obj
- console.log(name1)
- console.log(name2)
- }
- {
- let arr = [1, 2, 3, 4, 5, 6, 7, 10]
- const { 0: a, 1: b, length } = arr
- console.log(a)
- console.log(b)
- console.log(length)
- }
- {
- const flover = {
- type: 'palm',
- height: 150,
- color: 'green',
- [prompt('Введите первый параметр для объекта "Цветок"')]: prompt('Введите описание этого параметра'),
- [prompt('Введите второй параметр для объекта "Цветок"')]: prompt('Введите описание этого параметра')
- }
- const { type, height, color, ...rest } = flover
- const floverCopy = { type, height, color }
- console.log(floverCopy)
- console.log(flover === floverCopy)
- }
- {
- fetch('https://open.er-api.com/v6/latest/USD').then(res => res.json())
- .then(data => {
- let startCurrency = prompt('Введите исходную валюту').toUpperCase()
- startCurrency = startCurrency in data.rates ? startCurrency : alert('такая валюта не поддерживается')
- let finishCurrency = prompt('Введите конечную валюту').toUpperCase()
- finishCurrency = finishCurrency in data.rates ? finishCurrency : alert('такая валюта не поддерживается')
- const summ = prompt('Введите сумму для обмена в исходной валюте')
- const { rates: { [startCurrency]: startCurrencValue } } = data
- const { rates: { [finishCurrency]: finishCurrencValue } } = data
- const result = (startCurrency === 'USD' ? summ * finishCurrencValue / startCurrencValue : summ * finishCurrencValue / startCurrencValue).toFixed(2)
- alert(isNaN(result) ? 'Вы ввели неправильно один или несколько араметров' : result)
- console.log(data)
- })
- }
- {
- fetch('https://open.er-api.com/v6/latest/USD').then(res => res.json())
- .then(data => {
- const currencies = Object.keys(data.rates)
- let str = '<select>'
- for (let currency of currencies) {
- str += `<option>${currency}</option>`
- }
- str += '</select>'
- document.write(str)
- console.log(data)
- })
- }
- {
- fetch('https://open.er-api.com/v6/latest/USD').then(res => res.json())
- .then(data => {
-
- const currencies = []
- for (const currency in data.rates) {
- currencies.push(currency)
- }
-
- let str = `<table style="text-align: center; border-collapse: collapse">`
- str += `<tr><td></td>`
- for (const currency of currencies) {
- str += `<td style="padding: 5px 10px;background-color: grey;">${currency}</td>`
- }
- str += `</tr>`
-
- let i = 0
- for (const [key, value] of Object.entries(data.rates)) {
- str += (i % 2) ? `<tr style = "background-color:#0000001f">` : `<tr>`
- i++
-
- str += `<td style="background-color: grey;">${key}</td>`
- for (const num of Object.values(data.rates)) {
- str += `<td style="padding: 5px 10px;">${(num / value).toFixed(2)}</td>`
- }
- str += `</tr>`
- }
- document.write(str)
- })
- }
- {
- const car = {
- "Name": "chevrolet chevelle malibu",
- "Cylinders": 8,
- "Displacement": 307,
- "Horsepower": 130,
- "Weight_in_lbs": 3504,
- "Origin": "USA",
- "in_production": false
- }
- let str = `<form>`
- for (let [key, value] of Object.entries(car)) {
- str += `<label>${key}: <input type="${typeof value === 'string' ? 'text' : typeof value === 'number' ? 'number' : 'checkbox'}" value="${value}" /></label></br></br>`
- }
- str += `</form>`
- document.write(str)
- }
- {
- const persons = [
- {
- name: 'Мария',
- fatherName: 'Ивановна',
- surname: 'Иванова',
- sex: 'female'
- },
- {
- name: 'Николай',
- fatherName: 'Иванович',
- surname: 'Иванов',
- age: 15
- },
- {
- name: 'Петр',
- fatherName: 'Иванович',
- surname: 'Иванов',
- married: true
- },
- ]
-
- const keys = []
- for (const child of persons) {
- for (const key in child) {
- if (!keys.includes(key)) {
- keys.push(key);
- }
- }
- }
-
- let str = `<table style="border-collapse: collapse; text-align: center;">`
- str += `<tr style="background-color: grey;">`
- for (let key of keys) {
- str += `<td style="border: 1px solid black; padding: 5px 10px">${key}</td>`
- }
- str += `</tr>`
-
- for (const child of persons) {
- str += `<tr>`
- for (const num of keys) {
- str += `<td style="border: 1px solid black; padding: 5px 10px">${(Object.keys(child)).includes(num) ? child[num] : ''}</td>`
- }
- str += `</tr>`
- }
- str += `</table>`
- document.write(str)
- }
- {
- const persons = [
- {
- "Name": "chevrolet chevelle malibu",
- "Cylinders": 8,
- "Displacement": 307,
- "Horsepower": 130,
- "Weight_in_lbs": 3504,
- "Origin": "USA"
- },
- {
- "Name": "buick skylark 320",
- "Miles_per_Gallon": 15,
- "Cylinders": 8,
- "Displacement": 350,
- "Horsepower": 165,
- "Weight_in_lbs": 3693,
- "Acceleration": 11.5,
- "Year": "1970-01-01",
- },
- {
- "Miles_per_Gallon": 18,
- "Cylinders": 8,
- "Displacement": 318,
- "Horsepower": 150,
- "Weight_in_lbs": 3436,
- "Year": "1970-01-01",
- "Origin": "USA"
- },
- {
- "Name": "amc rebel sst",
- "Miles_per_Gallon": 16,
- "Cylinders": 8,
- "Displacement": 304,
- "Horsepower": 150,
- "Year": "1970-01-01",
- "Origin": "USA"
- },
- ]
- const keys = []
- for (const child of persons) {
- for (const key in child) {
- if (!keys.includes(key)) {
- keys.push(key);
- }
- }
- }
- let str = `<table style="border-collapse: collapse; text-align: center;">`
- str += `<tr style="background-color: grey;">`
- for (let key of keys) {
- str += `<td style="border: 1px solid black; padding: 5px 10px">${key}</td>`
- }
- str += `</tr>`
- for (const child of persons) {
- str += `<tr>`
- for (const num of keys) {
- str += `<td style="border: 1px solid black; padding: 5px 10px">${(Object.keys(child)).includes(num) ? child[num] : ''}</td>`
- }
- str += `</tr>`
- }
- str += `</table>`
- document.write(str)
- }
|