123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- //html tree
- let obj = {
- body: {
- tagName: 'body',
- attrs: {},
- paired: true,
- subTags: [
- {
- tagName: 'div',
- attrs: {},
- paired: true,
- subTags: [
- {
- tagName: 'span',
- attrs: {},
- paired: true,
- text: 'Enter data please:',
- },
-
- {
- tagName: 'br',
- paired: false
- },
-
- {
- tagName: 'input',
- attrs: {
- type: 'text',
- id: 'name'
- },
- paired: false
- },
-
- {
- tagName: 'input',
- attrs: {
- type: 'text',
- id: 'surname'
- },
- paired: false
- }
- ]
- },
- {
- tagName: 'div',
- attrs: {},
- paired: true,
- subTags: [
- {
- tagName: 'button',
- attrs: {
- id: 'ok'
- },
- paired: true,
- text: 'Ok'
-
- },
- {
- tagName: 'button',
- attrs: {
- id: 'cancel'
- },
- paired: true,
- text: 'Cancel'
- },
- ],
- },
- ]
- }
- }
- console.log(`<button id='cancel'> innerText:`, obj.body.subTags[1].subTags[1].text)
- console.log(`<input type='text' id='surname'> id:`, obj.body.subTags[0].subTags[3].attrs.id)
- //declarative fields
- var notebook = {
- brand: prompt('Notebook brand:','') || "HP",
- type: prompt('Notebook type:','') || "440 G4",
- model: prompt('Notebook model:','') || "Y7Z75EA",
- ram: +prompt('Notebook ram:','') || 4,
- size: prompt('Notebook size:','') || "14",
- weight: +prompt('Notebook weight:','') ||1.8,
- resolution: {
- width: +prompt('Notebook width:','') || 1920,
- height: +prompt('Notebook height','') || 1080,
- },
- };
- console.log(notebook)
- var phone = {
- brand: prompt('Phone brand:','') || "meizu",
- model: prompt('Phone model:','') || "m2",
- ram: +prompt('Phone amount of ram:','') || 2,
- color: prompt('Phone color','') || "black",
- };
- console.log(phone)
- var person = {
- Name: prompt('Person name:','') || 'Donald',
- surname: prompt('Person surname:','') || "Trump",
- married: confirm('is married?'),
- }
- console.log(person)
- //object links
- notebook.owner = phone.owner = person
- person.phone = phone
- person.notebook = notebook
- console.log(phone, notebook)
- console.log(person.phone.owner.notebook.owner.phone == person.phone )
- //imperative array fill 3
- let imperatve = [prompt('input array[0] element','')||0, prompt('input array[1] element','')||1, prompt('input array[2] element','')||2]
- console.log(imperatve)
- //while confirm
- while(!confirm('break the loop?')){}
- //array fill
- let arrayFill = []
- for(let i = 0, str; i < arrayFill.length+1; i++) {
- str = prompt('input array element','')
- if(!str && str !== '') {
- break;
- } else {
- arrayFill.push(str)
- }
- }
- console.log(arrayFill)
- let arrayNoPush = []
- for(let i = 0, str2; i < arrayNoPush.length+1; i++) {
- str2 = prompt('input arrayNoPush element','')
- if(!str2 && str2 !== '') {
- break;
- } else {
- arrayNoPush[arrayNoPush.length] = str2
- }
- }
- console.log(arrayNoPush)
- //infinite probability
- let trys = 0
- while(true) {
- trys++
- let rand = Math.random()
- if(rand > 0.9) {
- alert(`Number of iterations: ${trys}`)
- break;
- }
- }
- //empty loop
- while(!prompt('Input smth and press OK to stop','')){}
- //progression sum
- let N = 10
- let step = 1
- let sum = 0
- for(let i = 1; i <= N; i++) {
- sum = sum + step
- step += 3
- }
- console.log('progression sum:', sum)
- //chess one line
- let strlen = 11
- let str = ''
- for(let i = 0; i < strlen; i++) {
- i % 2 === 0? str += ' ' : str += '#'
- }
- console.log(str, str.length)
- //numers
- let numbers = ''
- for(let i = 0; i < 10; i++) {
- for(let i = 0; i < 10; i++) {
- numbers += `${i}`
- }
- numbers += '\n'
- }
- console.log(numbers)
|