Browse Source

hw2 part 1 done

miskson 2 years ago
parent
commit
6ee4d9b8b5
1 changed files with 157 additions and 21 deletions
  1. 157 21
      hw2/script1.js

+ 157 - 21
hw2/script1.js

@@ -1,29 +1,29 @@
-//assign: evaluation 
+// //assign: evaluation 
 var a = 5;
 var b, c;
 
-//if we delete brackets functionality is same
-// b = (a * 5);
-// b = (c = b/2);
-// a = 5
-// b = 12,5
-// c = 12,5
+// //if we delete brackets functionality is same
+// // b = (a * 5);
+// // b = (c = b/2);
+// // a = 5
+// // b = 12,5
+// // c = 12,5
 
 //one line variant
 c = b = (a * 5) / 2;
 
-// forgot one semicolon!
-// for(let i = 0 i < 5; i++) {
-//     console.log(i)
-// }
-// wrong usage of semicolon
-//let a; b = 5;
-//b = 5 c = b + 1;
+// // forgot one semicolon!
+// // for(let i = 0 i < 5; i++) {
+// //     console.log(i)
+// // }
+// // wrong usage of semicolon
+// //let a; b = 5;
+// //b = 5 c = b + 1;
 
-//semicolon logic errors
-// if(a === 5) {
-//     console.log('FIVE!')
-// }else; console.log('not five(')
+// //semicolon logic errors
+// // if(a === 5) {
+// //     console.log('FIVE!')
+// // }else; console.log('not five(')
 
 //GET YEAR TASK:
 function getAge(age, currentYear = new Date().getFullYear()) {
@@ -98,14 +98,12 @@ function oddInformer() {
         }
     }
 }
-oddInformer()
 
 //greet user using alert() and prompt()
 function greeting() {
     let name = prompt("Hey user, what's your name")
     alert(`Hello, ${name? name : 'Namless One...'}`)
 }
-greeting()
 
 //check if text contains desired words 
 function lexis(string, word) {
@@ -114,4 +112,142 @@ function lexis(string, word) {
     } else {
         return false
     }
-}
+}
+
+let quest1 = confirm('are you a human being?')
+let quest2 = confirm('can you fly?')
+
+if(quest1) {
+    if(quest2) {
+        alert('wow, you are Superman!')    
+    } else {
+        alert('Congrats, you are a real human being...')
+    }
+} else {
+    if(quest2) {
+        alert('so u must be a bird or smth :/')
+    } else {
+        alert('is machine spirit talking to me?')
+    }
+}
+
+let inMyBag = ['shoes', 'shorts', 'shirt', 'laptop', 'charger', 'copybook', 'pen', 'water-bottle']
+let answers = [quest1, quest2]
+
+//toying with arrays
+let plus = [1, 2]
+plus[2] = plus[0] + plus[1]
+console.log(plus)
+
+let plusStr = ['hello', 'My', 'World',]
+plusStr[plusStr.length] = plusStr[0] + plusStr[1] + plusStr[2]
+console.log(plusStr)
+
+//toying with objects
+let keyboard = {
+    model: 'sven slim 303',
+    type: 'membrane',
+    price: '5$'
+}
+
+let guitar = {
+    type: 'electric',
+    form: 'stratocaster',
+    strings: 6,
+    manufacturer: 'Fender'
+}
+
+keyboard.price = '10$'
+guitar['form'] = 'telecaster'
+
+//add brackets
+var age = +prompt("Сколько вам лет?","");
+if (age < 18 && age > 0){
+    alert("школьник");
+} else {
+    if (age >= 18 && age < 30){
+        alert("молодежь");
+    } else {
+        if (age >= 30 && age < 45){
+            alert("зрелость");
+        } else {
+            if (age >= 45 && age < 60){
+                alert("закат");
+            } else { 
+                if (age >= 60 && age <= 150 ) {
+                    alert("как пенсия?");
+                } else {
+                    alert("то ли киборг, то ли ошибка");
+                }
+            }
+        }
+    }
+}
+
+//Comparison: sizes
+let rusSize = prompt('Введите НАШ формат размера для переводa на на Американский формат','')
+let usSize = [
+    {
+        number: [6],
+        men: 'S',
+        woman:['XXS']
+    },
+    {
+        number: [8, 10],
+        men: 'M',
+        woman:['XXS', 'XS']
+    },
+    {
+        number: [12, 14],
+        men: 'L',
+        woman:['S', 'M']
+    },
+    {
+        number: [16, 18],
+        men: 'XL',
+        woman:['L','XL']
+    },
+    {
+        number: [20, 22],
+        men: 'XXL',
+        woman:['XXL', 'XXXL']
+    },
+]
+
+if(+rusSize && +rusSize >= 40 && +rusSize <= 56) {
+    rusSize = +rusSize
+    let flag = 0
+    if(rusSize % 2 !== 0) {
+        rusSize--
+        flag++
+    }
+    for(let i = 0; i < usSize.length; i++) {
+        let temp = usSize[i].number.findIndex(element => { return element === (rusSize - 34)})
+        if(temp >= 0) {
+            alert(`
+                ${rusSize+flag}-й размер в американском формате:
+                ------------------------------------------
+                    Размер: ${usSize[i].number[temp]}
+                    Мужчины: ${usSize[i].men}
+                    Женщины: ${usSize[i].woman[temp]}
+                ------------------------------------------
+            `)
+            break;
+        }
+    }
+} else {
+    alert('Неправильный размер.')
+}
+
+//Ternary
+alert(`${confirm('Вы мужчина?')? 'Вы мужчина.':'Вы женщина.'}`)
+
+//flats
+function flats(floors, flatsPerFloor, flatNumber) {
+    let info = {
+        flat: flatNumber,
+        building: Math.ceil(flatNumber/(floors * flatsPerFloor)),
+    }
+    info.floor = flatNumber/flatsPerFloor > floors? Math.ceil(flatNumber/flatsPerFloor)-floors*(info.building-1) : Math.ceil(flatNumber/flatsPerFloor);
+    return info;
+}