anton123 hace 2 años
padre
commit
a659c2f249

+ 2 - 9
HW 4 Операции, Типы, Сравнение, Условия и Логические операторы.2.js

@@ -139,16 +139,9 @@ let user = prompt("Введите камень, ножницы или бумаг
 let arr = [
     "камень",
     "ножницы",
-    "бумага",
-    "камень",
-    "ножницы",
-    "бумага",
-    "камень",
-    "ножницы",
-    "бумага",
-    "камень",
+    "бумага"
 ];
-let number = Math.floor(Math.random()*10)
+let number = Math.floor(Math.random()*3)
 numberArr = arr[number]
 if (user==numberArr) {
     alert("У меня "+numberArr+" НИЧЬЯ")

+ 12 - 9
Массивы.js

@@ -31,7 +31,6 @@
 
 //Multiply table
 {
-    //const arr = [[],[0,1,2,3,4,5,6,7,8,9,10],[0,2,4,6,8,10,12,14,16,18,20],[0,3,6,9,12,15,18,21,24,27,30],[0,4,8,12,16,20,24,28,32,36,40],[0,5,10,15,20,25,30,35,40,45,50]]
     const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
     console.log(arr[3][4])// ответ 12
 }
@@ -178,12 +177,13 @@
     const currencies = ["USD", "EUR", "GBP", "UAH"]
     let   str = "<table border='1'>"
     for (let currency of currencies){ 
-        str += '<tr>'+currency+'</tr>'
+        str += '<tr>'
         console.log(currency)
         for (let letter of currency){ 
             str += '<td>'+letter+'</td>'
             console.log(letter)
         }
+        str += '</tr>'
     }
     str+= "</table>"
     document.write(str)
@@ -193,14 +193,12 @@
 {
     const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
     let   str = "<table border='1'>"
-    let   i   = 0
     for (let currency of arr){
-        str += '<tr>'+currency+'</tr>'
-        console.log(currency)
+        str += '<tr>'
         for (let letter of currency){
             str += '<td>'+letter+'</td>'
-            console.log(letter)
         }
+        str+= '</tr>'
     }
     str+= "</table>"
     document.write(str)
@@ -228,11 +226,16 @@
     alert(arr)
 }
 
+
 //Beep Lexics
 {
-    const motherWord = ['дурак']
-    const arr = prompt('Введите строку').split(' ')
-    let resultArr = arr.map(x => x===motherWord[0] ?x='BEEP':x=x).join(' ')//понимаю что это не решение, но ничего другого не придумал
+    const arr = ['бляха', 'муха', "пляха", "шабля"]
+    let motherWord = prompt('Введите строку').split(' ')
+    let arr2 = []
+    for (let el of arr){
+        motherWord = motherWord.map(x => x===el ?x='BEEP':x)
+    }
+    alert(motherWord.join(' '))
 }
 
 

+ 151 - 2
Обьекты.js

@@ -181,6 +181,155 @@ body.children[1].children[1].parent = body.children[1];
         size: "4800/150/130",
         fuel: "petrol",
       };
-      const obj= {...ford}
-      delete obj[prompt('Введите ключ для удаления')]
+      let key = prompt('Введите ключ для удаления')
+      const {[key]:x, ...obj} = ford 
+      console.log(obj)
 }
+
+
+
+//Currency real rate
+{
+    fetch('https://open.er-api.com/v6/latest/USD').then(res => res.json())
+    .then(data => {
+        let currency = prompt('Введите исходную валюту').toUpperCase()
+        let currency2 = prompt('валюту, в которую происходит конвертация').toUpperCase()
+        let sum = +prompt('Введите сумму в '+currency2)
+        let rates1 = data.rates[currency]
+        let rates2 = data.rates[currency2]
+        data = (rates1/rates2)*sum
+        if (currency && currency2 && sum && data){
+        alert('Результат '+data+' '+currency)}
+        else{alert('Ошибка')}
+       })
+}
+
+
+
+//Currency drop down
+{
+    fetch('https://open.er-api.com/v6/latest/USD').then(res => res.json())
+    .then(data => {
+        let key = data.rates
+        key = Object.keys(key)
+        key = key.map(x=> "<option>"+x+"</option>")
+        key = '<select>'+key+'</select>'
+        console.log(document.write(key))
+       })
+}
+
+
+//Currency table
+{
+    fetch('https://open.er-api.com/v6/latest/USD').then(res => res.json())
+    .then(data => {
+        let dataObj = data.rates
+        let arrValues = Object.values(dataObj)
+        let arrKeys = Object.keys(dataObj)
+        let arrData  = []
+        let i = 0
+        for(let valuesEl of arrValues){
+            arrData.push(arrValues.map(x=>(valuesEl/x).toFixed(3)))
+            arrData[i].unshift(arrKeys[i])
+            i++
+        }
+        arrKeys.unshift('')
+        arrData.unshift(arrKeys)
+        let   currencyTable = "<table border='1'>"
+        for (let arrEl of arrData){
+            currencyTable += '<tr>'
+            for (let cell of arrEl){
+                currencyTable += '<td>'+cell+'</td>'
+            }
+            currencyTable+= '</tr>'
+        }
+        currencyTable+= "</table>"
+        document.write(currencyTable)
+    })
+}
+
+
+
+//Form
+{
+    const car = {
+        "Name":"chevrolet chevelle malibu",
+        "Cylinders":8,
+        "Displacement":307,
+        "Horsepower":130,
+        "Weight_in_lbs":3504,
+        "Origin":"USA",
+        "in_production": false
+    }
+    let keysArrCar = Object.keys(car)
+    let valuesArrCar = Object.values(car)
+    let i = 0
+    let strType
+    let formObjCar = '<form>\n'
+    for (let a of keysArrCar){
+        if (typeof valuesArrCar[i]=='string'){
+            strType = 'text'
+        }
+        else if(typeof valuesArrCar[i]=='boolean'){
+            strType = 'checkbox'
+        }
+        else{strType=typeof valuesArrCar[i]}
+        formObjCar += '    <label>'+a+': <input type="'+strType+'" value="'+valuesArrCar[i]+'"/></label>\n'
+        i++
+    }
+    formObjCar += '</form>'
+    console.log(formObjCar)
+}
+
+
+//Table
+// На тестовых данных проверено
+{
+    const persons = [
+        {
+            name: 'Мария',
+            fatherName: 'Ивановна',
+            surname: 'Иванова',
+            sex: 'female'
+        },
+        {
+            name: 'Николай',
+            fatherName: 'Иванович',
+            surname: 'Иванов',
+            age: 15
+        },
+        {
+            name: 'Петр',
+            fatherName: 'Иванович',
+            surname: 'Иванов',
+            married: true
+        },
+    ]
+    let i = 0
+    let arrKeys = []
+    for (let x of persons){
+        arrKeys += Object.keys(persons[i])+','
+        i++
+    }
+    arrKeys = arrKeys.split(',').slice(0,-1)
+    const makeUniq = (arr) => {
+        return arr.filter((el1, el2) => arr.indexOf(el1) === el2);
+        }
+    arrKeys = makeUniq(arrKeys)
+    let arrValue = []
+    for (let objPersons of persons){
+        arrValue.push(arrKeys.map(el=>objPersons[el]===undefined?objPersons[el]=' ':objPersons[el]))
+    }
+    arrValue.unshift(arrKeys)
+    
+    let   arrTable = "<table border='1'>"
+            for (let arrEl of arrValue){
+                arrTable += '<tr>'
+                for (let cell of arrEl){
+                    arrTable += '<td>'+cell+'</td>'
+                }
+                arrTable+= '</tr>'
+            }
+            arrTable+= "</table>"
+    document.write(arrTable)
+}