Browse Source

task execution continues

miskson 3 years ago
parent
commit
0ba99d7ddb
1 changed files with 111 additions and 32 deletions
  1. 111 32
      hw2/script2.js

+ 111 - 32
hw2/script2.js

@@ -67,7 +67,7 @@
 // }
 
 //switch: if
-let color = prompt("Введите цвет","");
+//let color = prompt("Введите цвет","");
 // switch (color){
 //     case "red": document.write("<div style='background-color: red;'>красный</div>");
 //     case "black": document.write("<div style='background-color: black; color: white;'>черный</div>");
@@ -78,41 +78,120 @@ let color = prompt("Введите цвет","");
 //     default: document.write("<div style='background-color: gray;'>Я не понял</div>");
 // }
 
-if(color === 'red') {
-    document.write("<div style='background-color: red;'>красный</div>");
-    document.write("<div style='background-color: black; color: white;'>черный</div>");    
-} else if(color === 'blue') {
-    document.write("<div style='background-color: blue;'>синий</div>");
-    document.write("<div style='background-color: green;'>зеленый</div>");
-} else if(color === 'green') {
-    document.write("<div style='background-color: green;'>зеленый</div>");
-} else if(color === 'black') {
-    document.write("<div style='background-color: black; color: white;'>черный</div>");
-} else {
-    document.write("<div style='background-color: gray;'>Я не понял</div>");
-}
+// if(color === 'red') {
+//     document.write("<div style='background-color: red;'>красный</div>");
+//     document.write("<div style='background-color: black; color: white;'>черный</div>");    
+// } else if(color === 'blue') {
+//     document.write("<div style='background-color: blue;'>синий</div>");
+//     document.write("<div style='background-color: green;'>зеленый</div>");
+// } else if(color === 'green') {
+//     document.write("<div style='background-color: green;'>зеленый</div>");
+// } else if(color === 'black') {
+//     document.write("<div style='background-color: black; color: white;'>черный</div>");
+// } else {
+//     document.write("<div style='background-color: gray;'>Я не понял</div>");
+// }
 
 //prompt: or
-let age = prompt('Введите свой возраст', '') || alert('Вы не ввели ничего!')
-if (age && isNaN(age) || age > 200 || age < 0){
-    alert('Вы ввели неверные данные!')    
-} else if(age){
-    age = age = Math.trunc(Number(age))
-    res = new Date().getFullYear() - age
-    alert(`Исходя из введенного вами возраста вы родились в ${res}г. либо ${res-1}г.`)
-}
+// let age = prompt('Введите свой возраст', '') || alert('Вы не ввели ничего!')
+// if (age && isNaN(age) || age > 200 || age < 0){
+//     alert('Вы ввели неверные данные!')    
+// } else if(age){
+//     age = age = Math.trunc(Number(age))
+//     res = new Date().getFullYear() - age
+//     alert(`Исходя из введенного вами возраста вы родились в ${res}г. либо ${res-1}г.`)
+// }
 
-//confirm: or this days
-confirm('шоппинг') || alert('ты-бяка') 
+// //confirm: or this days
+// confirm('шоппинг') || alert('ты-бяка') 
 
-//confirm: if this days
-if(!confirm('шоппинг')) {
-    alert('ты-бяка')
+// //confirm: if this days
+// if(!confirm('шоппинг')) {
+//     alert('ты-бяка')
+// }
+
+// //triple prompt
+// let Name = prompt('your Name:','')
+// let surname = prompt('your Surname:','')
+// let patronymic = prompt('your Patronymic:','')
+// alert(`${surname} ${Name} ${patronymic}`)
+
+// //default: or
+// let defaultName = prompt('your Name:','') || 'Иван'
+// let defaultSurname = prompt('your Surname:','') || 'Иванов'
+// let defaultPatronymic = prompt('your Patronymic:','')  || 'Иванович'
+// alert(`${defaultSurname} ${defaultName} ${defaultPatronymic}`)
+
+// // default: if
+// if(Name) {
+//     Name = Name
+// } else {
+//     Name = 'Ivan'
+// }
+// if(surname) {
+//     surname = surname
+// } else {
+//     surname = 'Ivanov'
+// }
+// if (patronymic) {
+//     patronymic = patronymic
+// } else {
+//     patronymic = 'Ivanovich'
+// }
+
+// alert(`Triple promt, but using "if else" to add default values:
+//     ${surname} ${Name} ${patronymic}`)
+
+// //login and password
+// if(prompt('login','') === 'admin') {
+//     alert('correct login')
+//     if(prompt('password','') === 'qwerty') {
+//         alert('correct password')
+//     } else {
+//         alert('wrong password')
+//     }
+// } else {
+//     alert('wrong login')
+// }
+
+//currency calc
+function truncateFraction (number) {
+    try {
+        let strNum = String(number).split('.')
+        if(strNum[1].length > 2) {
+            strNum[1] = strNum[1].slice(0, 2)
+        }
+        return Number(strNum.join('.'))
+    } catch (e) {
+        return number
+    }
 }
 
-//triple prompt
-let Name = prompt('your Name:','')
-let surname = prompt('your Surname:','')
-let fathersname = prompt('your Fathersname:','')
-alert(surname, fathersname, Name)
+let curr = prompt('type currency: "eur" or "usd"','')
+let transferLog = {
+    initial: 'hrn',
+    to: ''
+}
+switch(curr) {
+    case 'eur':
+        transferLog.to = 'eur'
+        curr = 0.033
+        break;
+    case 'usd':
+        transferLog.to = 'usd'
+        curr = 0.038
+        break;
+}
 
+if(transferLog.to === 'eur' || transferLog.to === 'usd') {
+    transferLog.money = prompt('input amount of hrn you want to transfer:', '')
+    if(!+transferLog.money) {
+        alert('invalid input')
+    } else {
+        transferLog.given = Number(transferLog.money)
+        transferLog.money = truncateFraction(transferLog.given * curr)
+        alert(`You've tansfered ${transferLog.given}${transferLog.initial} to ${transferLog.money}${transferLog.to}`)
+    }
+} else {
+    alert('invalid input')
+}