Browse Source

HW YB2NKR8B2LL done

Varvara Huza 3 years ago
parent
commit
6116ba8d29
3 changed files with 315 additions and 3 deletions
  1. 3 3
      Homework_3/main.js
  2. 13 0
      Homework_5/index.html
  3. 299 0
      Homework_5/main.js

+ 3 - 3
Homework_3/main.js

@@ -190,13 +190,13 @@ if (age < 0) {
   if (age < 18) {
     alert("школьник")
   } else {
-    if (age >= 18 && age <= 30) {
+    if (age <= 30) {
       alert("молодеж")
     } else {
-      if (age > 30 && age <= 45) {
+      if (age <= 45) {
         alert("зрелость")
       } else {
-        if (age > 45 && age <= 60) {
+        if (age <= 60) {
           alert("закат")
         } else {
           if (age > 60) {

+ 13 - 0
Homework_5/index.html

@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <script src='main.js'></script>
+</head>
+<body>
+    
+</body>
+</html>

+ 299 - 0
Homework_5/main.js

@@ -0,0 +1,299 @@
+//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[1].subTags[1].attrs.id
+
+//declarative fields
+    // let laptop = {
+    //     brand: prompt('Enter a brand of the laptop'),
+    //     type:  prompt('Enter a type of the laptop'),
+    //     model: prompt('Enter a model of the laptop'),
+    //     ram: +prompt('Enter a ram size of the laptop'),
+    //     size: prompt('Enter a size of the laptop'),
+    //     weight: +prompt('Enter a weight of the laptop'),
+    //     resolution: {
+    //         width: +prompt('Enter a display resolution (width) of the laptop'),
+    //         height: +prompt('Enter a display resolution (height) of the laptop'),
+    //     },
+    // }
+
+    // let phone = {
+    //     brand: prompt('Enter a brand of the phone'),
+    //     model: prompt('Enter a model of the phone'),
+    //     ram: +prompt('Enter a ram size of the phone'),
+    //     color: prompt('Enter a color of the phone'),
+    // }
+
+    // let person = {
+    //     name: prompt('Enter the person\'s name'),
+    //     surname: prompt('Enter the person\'s surname'),
+    //     married: confirm('Is this person married?'),
+    // }
+
+//object links 
+    // person.laptop = laptop
+    // person.smartphone = phone
+    // laptop.owner = person
+    // phone.owner = person
+
+//imperative array fill 3
+    // let array = []
+    // for (let i = 0; i < 3; i++) {
+    //     array[i] = prompt('?')
+    // }
+
+//while confirm
+    // let counter = 0
+    // while (!confirm('Нажмите отмена')){
+    //     counter++
+    //     if (counter == 5) {
+    //         alert('Еще не надоело?')
+    //     }
+    // }; 
+
+//array fill
+    // let zoo = []
+    // while(true) {
+    //     let newAnimal = prompt('Введите название зверушки')
+    //     if(newAnimal == null) {
+    //         break;
+    //     }
+    //     zoo.push(newAnimal);
+    // }
+
+//array fill nopush
+    // let zoo = []
+    // let i = 0
+    // while(true) {
+    //     let newAnimal = prompt('Введите название зверушки')
+    //     if(newAnimal == null) {
+    //         break;
+    //     }
+    //     zoo[i] = newAnimal
+    //     i++
+    // }
+
+//infinite probability
+    // let counter = 0
+    // while (true) {
+    //     counter++
+    //     if (Math.random() > 0.9) {
+    //         alert(counter)
+    //         break
+    //     }
+    // }
+
+//empty loop
+    // while (prompt('Скинь сотку на карту плез') == null);
+
+//progression sum
+    // let n = +prompt('До какого числа хотите считать?')
+    // let sum = 0
+    // for (let i = 1; i < n; i += 3) {
+    //     sum += i;
+    // }
+    // alert(sum)
+
+//chess one line 
+    // let length = prompt ('Укажите длину строки пожалуйста прошу вас')
+    // let line = '';
+    // for (let i = 0; i < length; i++) {
+    //     if (i % 2 == 0) {
+    //         line += ' '
+    //     } else {
+    //         line += '#'
+    //     }
+    // }
+    // console.log(`"${line}"`)
+
+//numbers 
+    // let string = ''
+    // for (let i = 0; i < 10; i++) {
+    //     for (let j = 0; j < 10; j++) {
+    //         string += j
+    //     }
+    //     string += '\n'
+    // }
+
+//chess 
+    // let length = +prompt ('Укажите размер поля (x)')
+    // let height = +prompt ('Укажите размер поля (y)')
+    // let line = '';
+    // for (let i = 0; i < height; i++ ) {
+    //     for (let j = 0; j < length; j++) {
+    //         if (i % 2 == 0) {
+    //             if (j % 2 == 0) {
+    //                 line += '.'
+    //             } else {
+    //                 line += '#'
+    //             }
+    //         } else {
+    //             if (j % 2 == 0) {
+    //                 line += '#'
+    //             } else {
+    //                 line += '.'
+    //             }
+    //         }
+    //     }
+    //     line += '\n'
+    // }
+    // console.log(line)
+
+//cubes 
+    // let n = +prompt('Сколько элементов в массиве?')
+    // let arr = [];
+    // for (let i = 0; i < n; i++) {
+    //     arr[i] = i**3
+    // }
+
+//multiply table
+let multiplyTable = []
+for (let i = 0; i <=10; i++) {
+    multiplyTable[i] = []
+    for (let j = 0; j <=10; j++) {
+        multiplyTable[i][j] = i * j
+    }
+}
+
+//matrix to html table
+document.write('<table>')
+for (let i = 0; i < multiplyTable.length; i++) {
+    document.write('<tr>')
+    if (i == 0) {
+        document.write ('<td>&#9959;</td>')
+    } else {
+        document.write('<td>' + i + '</td>')
+    }
+    for (let j = 1; j < multiplyTable[i].length; j++) {
+        if (i == 0) {
+            document.write('<td>' + multiplyTable[1][j] + '</td>')
+        } else {
+            document.write('<td>' + multiplyTable[i][j] + '</td>')
+        }
+
+    }
+    document.write('</tr>')
+}
+document.write('</table>')
+
+//Задание на синий пояс: Треугольник
+let triangleHeight = +prompt('Высота треугольника: ')
+let triangle = ''
+for (let i = 0; i < triangleHeight; i ++) {
+    let row = ''
+    let dot = ''
+    let hash = ''
+    for (let j = triangleHeight - (i + 1); j > 0; j--) {
+        dot += '.'
+    }
+
+    for (let j = 0; j < 2 * i + 1; j++) {
+        hash += '#'
+    }
+    row += (dot + hash + dot + '\n')
+    triangle += row;
+}
+console.log(triangle)
+
+//Задание на черный пояс: Электронная гадалка
+//комментарии пишу чисто для себя, чтобы не запутаться
+let predictArray = [];
+for (let f = 0; f <=1; f++) {
+    predictArray[f] = [];
+    for (let u = 0; u <= 1; u++) {
+        predictArray[f][u] = [];
+        for (let c = 0; c <= 1; c++) {
+            predictArray[f][u][c] = [];
+            for (let k = 0; k <= 1; k++) {
+                predictArray[f][u][c][k] = -1;
+            }
+        }
+    }
+}
+
+let history = [1, 1, 1, 1,]
+let prediction = predictArray[history[0]][history[1]][history[2]][history[3]];
+let points = 0;
+let counter = 0;
+while (true) {
+    //Делаем предсказание, выводим его в консоль
+    if (prediction === -1) {
+        console.log('Предсказание гадалки: ' + Math.round(Math.random()))
+    } else {
+        console.log('Предсказание гадалки: ' + prediction)
+    }
+
+    //просим пользователя сделать его ход и выводим в консоль 
+    let userNumber = prompt('Введите 0 или 1')
+    if (userNumber === null || userNumber === '') {
+        break
+    }
+    console.log('Ввод пользователя:' + userNumber)
+    counter++
+
+    //если предсказание было правдивым, то отнимаем очки у пользователя
+    if (prediction == userNumber) {
+        points--
+    } else {
+        points++
+    }
+    alert('Ваш счёт: ' + points)
+
+    //записываем ввод пользователя в массив предсказаний и в историю
+    prediction = +userNumber
+    history.shift()
+    history.push(+userNumber)
+}
+
+//выводим кол-во набранных (ну или потерянных) очков и кол-во ходов
+alert('Количество ходов: ' + counter + '. Ваш счёт: ' + points)