Browse Source

HW<4> done

Anton 1 year ago
parent
commit
6e4c6a73ca
6 changed files with 522 additions and 62 deletions
  1. 2 0
      HW3/index.html
  2. 121 14
      HW3/myjs.js
  3. 0 48
      HW3/training.html
  4. 13 0
      HW4/index.html
  5. 299 0
      HW4/myjs.js
  6. 87 0
      training.html

+ 2 - 0
HW3/index.html

@@ -8,6 +8,8 @@
 </head>
 <body>
     <script src="myjs.js"></script>
+
+    
     
 </body>
 </html>

+ 121 - 14
HW3/myjs.js

@@ -1,4 +1,6 @@
-/* switch: sizes */
+let job = prompt("Какую работу вы хотите посмотреть?")
+switch(job) {
+    case "switch: sizes" :
 
         let country = prompt("Какой размер обуви вы хотите узнать: Европейский/США?")
         let size = prompt("Введите длину вашей стопы в см.") 
@@ -52,7 +54,9 @@
         }
     }
 
-/* switch: if */
+    break;
+
+    case "switch: if" :
 
     let color = prompt("Введите цвет", "");
     if (color == "red"){
@@ -71,7 +75,9 @@
         alert(document.write("<div style='background-color: gray;'>Я не понял</div>"))
     }
 
-/* prompt: or */
+    break;
+    
+    case "prompt: or" :
 
     let age = prompt("Укажите Ваш возраст.")
     let years = 2022;
@@ -83,11 +89,15 @@
         alert(YearOfBirth)
     }
 
-/* confirm: or this days */
+    break;
+
+    case "confirm: of this days" :
 
     let shopping1 = confirm("шопинг?") || alert("ты - бяка")
 
-/* confirm: if this days */
+    break;
+
+    case "confirm: if this days" :
 
     let shopping = confirm("шопинг?");
     if (shopping){
@@ -97,7 +107,9 @@
         alert("ты - бяка")
     }
 
-/* triple prompt */
+    break;
+
+    case "triple prompt" :
 
     let surname = prompt("Напишите Вашу Фамилию.")
     let lastname = prompt("Напишите Ваше Имя.")
@@ -105,7 +117,9 @@
     let fullName = surname + " " + lastname + " " + patronymic
     alert(fullName)
 
-/* default: or */
+    break;
+
+    case "default: or" :
 
     let surname1 = prompt("Напишите Вашу Фамилию")
     let name1 = prompt("Напишите Ваше Имя")
@@ -115,7 +129,9 @@
     patronymic1 = patronymic1 || "Иванович"
     alert(surname1 + ' ' + name1 + ' ' + patronymic1)
 
-/* default: if */
+    break;
+
+    case "default: if" :
 
     let surname2 = prompt("Напишите Вашу Фамилию")
     let name2 = prompt("Напишите Ваше Имя")
@@ -133,7 +149,10 @@
 
     alert(surname2 + ' ' + name2 + ' ' + patronymic2)
 
-/* login and password */
+    break;
+
+
+    case "login ande password" :
 
     let login = prompt("Введите логин.");
     if (login == "admin"){
@@ -149,7 +168,9 @@
         alert("Ошибка")
     }
 
-/* currency calc */
+    break;
+
+    case "currency calc" :
 
     let currency = prompt("Какую валюты Вы хотите конвертировать? usd/eur")
     let sum = prompt("Введите сумму в грн.")
@@ -162,8 +183,10 @@
             well = 37
         }
     alert(sum / well)
+    
+    break;
 
-/*  currency calc: improved */
+    case "currency calc: improved" :
 
         let currency1 = prompt("Какую валюты Вы хотите конвертировать? usd/eur").toLowerCase()
         let sum1 = prompt("Введите сумму в грн.")
@@ -177,7 +200,9 @@
         }
         alert(sum1 / well1)
 
- /* currency calc: two rates */
+    break;
+
+    case "currency calc: two rates" :
 
     let currency2 = prompt("Какую валюты Вы хотите конвертировать? usd/eur").toLowerCase()
     let sum2 = prompt("Введите сумму в грн.")
@@ -199,7 +224,9 @@
         alert(eurResult)
     }
 
-/* currency calc: if */
+    break;
+
+    case "currency calc: if" :
 
     let currency3 = prompt("Какую валюты Вы хотите конвертировать? usd/eur").toLowerCase()
     let sum3 = prompt("Введите сумму в грн.")
@@ -218,4 +245,84 @@
         ? sum3 / eurBuy3 : sum3 / eurSale3
         alert(eurResult3)
 
-    }
+    }
+
+    break;
+
+
+    case "scissors" :
+
+        let userRandom = prompt("Выберите: Камень/Ножницы/Бумага")
+            if (userRandom === "Камень"){
+                userRandom = 1
+            }else if (userRandom === "Ножницы"){
+                userRandom = 2
+            }else if (userRandom === "Бумага"){
+                userRandom = 3
+            }
+
+        let random = Math.random() *3
+        let computerRandom = Math.ceil(Math.round(random))
+            if (computerRandom === 1){
+                alert("Компьютер выбрал Камень")
+            }else if (computerRandom === 2){
+                alert("Компьютер выбрал Ножницы")
+            }else if (computerRandom === 3){
+                alert("Компьютер выбрал Бумагу")
+            }
+
+        if (userRandom === 1 && computerRandom === 1 || userRandom === 2 && computerRandom === 2 || userRandom === 3 && computerRandom === 3 ){
+            alert("Ничья!")
+        }else if (userRandom === 1 && computerRandom === 2 || userRandom === 2 && computerRandom === 3 || userRandom === 3 && computerRandom === 1){
+            alert("Вы победили!")
+        }else if (userRandom === 1 && computerRandom === 3 || userRandom === 2 && computerRandom === 1 || userRandom === 3 && computerRandom === 2){
+            alert("Вы проиграли!")
+        }
+
+    break;
+
+    case "задание на синий пояс" :
+
+
+        let currency4 = prompt("Какую валюты Вы хотите конвертировать? usd/eur").toLowerCase()
+        let sum4 = prompt("Введите сумму в грн.")
+        let ratios = {
+            usd: 25.6,
+            eur: 29
+        }
+    
+            if (currency4 == "usd"){
+                alert(sum4 / ratios["usd"])
+            }
+            else if(currency4 == "eur"){
+                alert(sum4 / ratios["eur"])
+            }
+
+    break;
+
+    case "real data" :
+
+
+    let currency5 = prompt("Какую валюты Вы хотите конвертировать? usd/eur").toLowerCase()
+    let sum5 = prompt("Введите сумму в грн.")
+
+        if (currency5 == "usd"){
+            fetch('https://open.er-api.com/v6/latest/USD')
+                .then(res => res.json())
+                .then(data => {
+                    alert(sum5 / data.rates.UAH)
+            
+            })
+        }
+        else if(currency5 == "eur"){
+            fetch('https://open.er-api.com/v6/latest/EUR')
+                .then(res => res.json())
+                .then(data => {
+                    alert(sum5 / data.rates.UAH)
+            
+            })
+        }
+
+        break;
+}
+    

+ 0 - 48
HW3/training.html

@@ -1,48 +0,0 @@
-<!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>
-</head>
-<body>
-    <script>
-    
-
-    let currency = prompt("Какую валюты Вы хотите конвертировать? usd/eur").toLowerCase()
-    let sum = prompt("Введите сумму в грн.")
-    let usdBuy = 35
-    let usdSale = 34.5
-    let eurBuy = 37
-    let eurSale = 36.5
-
-    if (currency == "usd"){
-        let usdResult = confirm("Если вы хотите совершить покупку - нажмите ОК, если продажу - ОТМЕНА.")
-        ? sum / usdBuy : sum / usdSale
-        alert(usdResult)
-    }
-    else if(currency == "eur"){
-        let eurResult = confirm("Если вы хотите совершить покупку - нажмите ОК, если продажу - ОТМЕНА.")
-        ? sum / eurBuy : sum / eurSale
-        alert(eurResult)
-
-    }
-
-    /* switch(currency) {
-        case "usd" :
-        let usdResult = confirm("Если вы хотите совершить покупку - нажмите ОК, если продажу - ОТМЕНА.")
-        ? sum / usdBuy : sum / usdSale
-        alert(usdResult)
-        break;
-
-        case "eur" :
-        let eurResult = confirm("Если вы хотите совершить покупку - нажмите ОК, если продажу - ОТМЕНА.")
-        ? sum / eurBuy : sum / eurSale
-        alert(eurResult)
-    } */
-    
-
-    </script>
-</body>
-</html>

+ 13 - 0
HW4/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>
+</head>
+<body>
+    <script src="myjs.js"></script>
+    
+</body>
+</html>

+ 299 - 0
HW4/myjs.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'][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: {}
+    };
+
+    var phone = {
+        brand: prompt("Enter a brand"),
+        model: prompt("Enter a model"),
+        ram: +prompt("Enter a ram"),
+        color: prompt("Enter a color"),
+        owner: {}
+    };
+    
+
+    var person = {
+        name: prompt("Enter a name"),
+        surname: prompt("Enter a surname"),
+        married: confirm("Are you a married?"),
+        smartphone: {},
+        laptop:{}
+    }
+
+/* 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 arr2 = [];
+        while (arr1) {
+            arr2.push(arr1 = prompt("Введите что-то"));
+            if (arr1 == null || false) {
+            break;
+            }
+        }
+
+/* array fill nopush */
+
+    let arr4 = [];
+        for (let i = 0; i != null; i++) {
+            arr4 = prompt('Напишите слово')
+                if (arr4 == null || false) {
+            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)

+ 87 - 0
training.html

@@ -0,0 +1,87 @@
+<!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>
+</head>
+<body>
+<script>
+
+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)
+
+
+</script>
+</body>
+</html>