123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- // html tree
- {
- let body = {
- tagName: "body",
- subTags: [
- {
- tagName: "div",
- subTags: [
- {
- tagName: "span",
- text: "Enter a data please:",
- },
- {
- tagName: "br",
- },
- {
- tagName: "input",
- attrs: {
- type: "text",
- id: "name",
- },
- },
- {
- tagName: "input",
- attrs: {
- type: "text",
- id: "surname",
- },
- },
- ],
- },
- {
- tagName: "div",
- subTags: [
- {
- tagName: "button",
- text: "OK",
- attrs: {
- id: "ok",
- },
- },
- {
- tagName: "button",
- text: "Cancel",
- attrs: {
- id: "cancel",
- },
- },
- ],
- },
- ],
- };
- console.log(body.subTags[1].subTags[1].text);
- console.log(body.subTags[0].subTags[3].attrs.id);
- // declarative fields and object links
- {
- var notebook = {
- brand: prompt("Введите марку ноутбука"),
- type: prompt("Введите тип"),
- model: prompt("Введите модель ноутбука"),
- ram: +prompt("Введите количесство оперативки"),
- size: +prompt("Введите диагональ экрана"),
- weight: +prompt("Вес ноутбука"),
- resolution: {
- width: +prompt("Ширина экрана ноутбука"),
- height: +prompt("Высота экрана ноутбука"),
- },
- owner: person,
- };
- var phone = {
- brand: prompt("Введите марку телефона"),
- model: prompt("Введите модель телефона"),
- ram: +prompt("Введите количество оперативки"),
- color: prompt("Введите цвет телефона"),
- owner: person,
- };
- var person = {
- name: prompt("Введите имя"),
- surname: prompt("Введите фамилию"),
- married: confirm("женат"),
- smartphone: phone,
- laptop: notebook,
- }
- }
- // imperative array fill 3
- {
- let arr = [];
- arr[0] = prompt('Введите первый элемент массива'),
- arr[1] = prompt('Введите второй элемент массива'),
- arr[2] = prompt('Введите третий элемент массива');
- }
- // while confirm
- let cycle = confirm();
- while (cycle == false) {
- cycle = confirm();
- if (cycle) {
- break;
- }
- }
- // array fill
- {
- let arr = [];
- let arrPush = []
- while (arr) {
- arrPush.push(arr = prompt())
- if (arr === null) {
- break;
- }
- }
- }
- // array fill nopush
- {
- let arrNoPush = []
- for (let i = 0; i != null; i++) {
- arrNoPush[i] = prompt("Введите для примера что-то!");
- if (arrNoPush[i] === null)
- break;
- }
- }
- // infinite probability
- {
- let number = 0;
- while (true) {
- let randomNumber = Math.random();
- number++;
- if (randomNumber > 0.9) {
- alert("количество итераций " + number);
- alert("Случайное число " + randomNumber);
- break;
- }
- }
- }
- // empty loop
- // progression sum
- for (let i = 0; i < 10000; i++) {
- console.log(i);
- }
- // chess one line
- {
- let i = '#';
- let str = " ";
- for (j = 0; j < 5; j++) {
- str += i + " ";
- }
- console.log(str);
- }
- // numbers
- {
- let numbers = "";
- for (let i = 0; i <= 9; i++) {
- for (let a = 0; a <= 9; a++) {
- numbers += a;
- }
- numbers += "\n";
- }
- console.log(numbers);
- }
- // chess
- {
- let boardChess = "";
- for (let i = 0; i < 10; i++) {
- for (let a = 0; a < 12; a++) {
- boardChess += (a % 2) == (i % 2) ? "." : "#";
- }
- boardChess += "\n";
- }
- console.log(boardChess);
- }
- // cubes
- for (let indexСubes = []; ;) {
- let index = indexСubes.length;
- let expon = index ** 3;
- indexСubes.push(expon);
- if (indexСubes.length == 20) {
- console.log(indexСubes);
- break;
- }
- }
- // multiply table
- let arr = Array(10);
- for (let i = 1; i < 10; i++) {
- arr[i] = [...Array(10)].map((_, j) => i * j);
- }
- console.log(arr[5][6]);
- console.log(arr[7][2]);
- // Задание на синий пояс: Треугольник,нужно еще пофиксить
- let i = 0,
- j = 0;
- let point = "",
- lattice = "";
- while (i <= 5) {
- point = "";
- lattice = "";
- for (j = 0; j < 5 - i; j++) point += ".";
- for (j = 0; j < 2 * i + 1; j++) lattice += "#";
- console.log(point + lattice + point);
- i++;
- }
-
- }
|