123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- /* 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',
- attrs: {
- id: 'ok'
- },
- text: 'OK'
- },
- {
- tagName: 'button',
- attrs: {
- id: 'cancel'
- },
- text: 'Cancel'
- },
- ]
- }
- ]
- }
- body.subTags[1].subTags[1].text
- body.subTags[0].subTags[1].attrs.id
- /* declarative fields */
- var 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: 'Anton'
- };
- var phone = {
- brand: prompt("Enter a brand"),
- model: prompt("Enter a model"),
- ram: +prompt("Enter a ram"),
- color: prompt("Enter a color"),
- owner: 'Anton'
- };
- var person = {
- name: prompt("Enter a name"),
- surname: prompt("Enter a surname"),
- married: confirm("Are you a married?"),
- smartphone: 'iPhone',
- laptop: 'Lenovo'
- }
- /* object links */
- person.smartphone = phone
- person.laptop = notebook
- notebook.owner = person
- phone.owner = person
- /* imperative array fill 3 */
- let arr = []
- arr[0] = prompt('Напишите слово')
- arr[1] = prompt('Напишите слово')
- arr[2] = prompt('Напишите слово')
- alert(arr)
- /* while confirm */
- let round;
- while (round != true) {
- round = confirm('Вы человек?');
- if (round) {
- break;
- }
- }
- /* array fill */
- let arr1 = [];
- let value;
- do {
- value = prompt("Введите что-то")
- if (value) {
- arr1.push(value);
- } else {
- break;
- }
- } while (value)
- /* array fill nopush */
- let arr4 = [];
- let value1;
- for (let i = 0; i != null; i++) {
- value1 = prompt('Напишите слово')
- if (value1) {
- arr4[i] = value1
- }
- else {
- break
- }
- }
- /* infinite probability */
- let random = Math.random();
- let result = 0;
- while (random) {
- random = Math.random();
- result += 1;
- if (random > 0.9) {
- alert("Компьютер выполнил " + result + " циклов.");
- break
- }
- }
- /* empty loop */
- do {
- } while (prompt('Напишите слово') == null || false)
- /* progression sum */
- var sum = 0;
- for (var i = 1; i <= 27; i = i + 3) {
- console.log(i);
- sum = sum + i;
- }
- console.log(sum)
- /* chess one line */
- let chessStr = ' ';
- for (let i = 0; i < 10; i++) {
- if (i % 2 === 0) {
- chessStr += " ";
- } else {
- chessStr += "#";
- }
- }
- console.log(chessStr)
- /* numbers */
- let numbers;
- for (let i = 0; i <= 10; i++) {
- for (let a = 0; a < 10; a++) {
- numbers = numbers + a;
- if (a == 9) {
- numbers = numbers + '\n'
- }
- }
- if (i == 10) {
- console.log(numbers);
- break;
- }
- }
- /* chess */
- let chess;
- for (let i = 0; i < 10; i++) {
- if (i > 0) chess += "\n";
- for (let j = 0; j < 12; j++) {
- if ((j + i) % 2 === 0) {
- chess += ".";
- } else {
- chess += "#";
- }
- }
- }
- console.log(chess)
- /* cubes */
- let index = [];
- for (let i = 0; i <= 10; i++) {
- index.push(i * i * i);
- }
- console.log(index)
- /* multiply table */
- let arr3 = []
- for (let i = 0; i <= 10; i++) {
- let arr4 = []
- arr3.push(arr4)
- for (let a = 0; a <= 10; a++) {
- arr4.push(i * a)
- }
- }
- console.log(arr3)
- /* Задание на синий пояс: треугольник */
- let delta = '';
- for (let i = 0; i < 1; i++) {
- for (let j = 0; j <= 11; j++) {
- if (j == 11) {
- delta = delta + '\n'
- }
- else if (j === 5) {
- delta = delta + '#'
- }
- else {
- delta = delta + '.'
- }
- }
- for (let j = 0; j <= 11; j++) {
- if (j == 11) {
- delta = delta + '\n'
- }
- else if (j === 4 || j === 5 || j === 6) {
- delta = delta + '#'
- }
- else {
- delta = delta + '.'
- }
- }
- for (let j = 0; j <= 11; j++) {
- if (j == 11) {
- delta = delta + '\n'
- }
- else if (j === 3 || j === 4 || j === 5 || j === 6 || j === 7) {
- delta = delta + '#'
- }
- else {
- delta = delta + '.'
- }
- }
- for (let j = 0; j <= 11; j++) {
- if (j == 11) {
- delta = delta + '\n'
- }
- else if (j === 2 || j === 3 || j === 4 || j === 5 || j === 6 || j === 7 || j === 8) {
- delta = delta + '#'
- }
- else {
- delta = delta + '.'
- }
- }
- for (let j = 0; j <= 11; j++) {
- if (j == 11) {
- delta = delta + '\n'
- }
- else if (j === 1 || j === 2 || j === 3 || j === 4 || j === 5 || j === 6 || j === 7 || j === 8 || j === 9) {
- delta = delta + '#'
- }
- else {
- delta = delta + '.'
- }
- }
- for (let j = 0; j <= 11; j++) {
- if (j == 11) {
- delta = delta + '\n'
- }
- else if (j === 0 || j === 1 || j === 2 || j === 3 || j === 4 || j === 5 || j === 6 || j === 7 || j === 8 || j === 9 || j === 10) {
- delta = delta + '#'
- }
- else {
- delta = delta + '.'
- }
- }
- }
- console.log(delta)
|