123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- 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
- }
- }
- var loop = true
- while(loop) {
- switch(prompt('input task name:', '')) {
- case 'switch: sizes':
- 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']
- },
- ]
-
- let rusSize = prompt('Введите НАШ формат размера для переводa на на Американский формат','')
- console.log(isNaN(rusSize))
- switch(!isNaN(rusSize) && +rusSize >= 40 && +rusSize <= 56) {
- case true:
- rusSize = +rusSize
- let flag = 0
-
- switch(rusSize % 2 !== 0) {
- case true:
- rusSize--
- flag++
- }
-
- for(let i = 0; i < usSize.length; i++) {
- let temp = usSize[i].number.findIndex(element => { return element === (rusSize - 34)})
- switch( temp >= 0) {
- case true:
- alert(`
- ${rusSize+flag}-й размер в американском формате:
- +---------------------------------------+
- Размер: ${usSize[i].number[temp]}
- Мужчины: ${usSize[i].men}
- Женщины: ${usSize[i].woman[temp]}
- +---------------------------------------+
- `)
- i = usSize.length
- break;
-
- default:
- continue;
- }
- }
- break;
-
- case false:
- alert('Неправильный размер.')
- break;
- }
- break;
-
- case 'switch: if':
- let color = prompt("Введите цвет","");
-
- 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>");
- }
- alert('aborting execution to make changes. Reload page to return to select mode')
- loop = false
-
- break;
-
- case '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}г.`)
- }
- break;
-
- case 'confirm: or this days':
- confirm('шоппинг') || alert('ты-бяка')
- break;
-
- case 'confirm: if this days':
- if(!confirm('шоппинг')) {
- alert('ты-бяка')
- }
- break;
-
- case 'triple prompt':
- let Name = prompt('your Name:','')
- let surname = prompt('your Surname:','')
- let patronymic = prompt('your Patronymic:','')
- alert(`${surname} ${Name} ${patronymic}`)
- break;
-
- case 'default: or':
- let defaultName = prompt('your Name:','') || 'Иван'
- let defaultSurname = prompt('your Surname:','') || 'Иванов'
- let defaultPatronymic = prompt('your Patronymic:','') || 'Иванович'
- alert(`${defaultSurname} ${defaultName} ${defaultPatronymic}`)
- break;
-
- case 'default: if':
- let NameIf = prompt('your Name:','')
- let surnameIf = prompt('your Surname:','')
- let patronymicIf = prompt('your Patronymic:','')
-
- if(NameIf) {
- NameIf = NameIf
- } else {
- NameIf = 'Ivan'
- }
- if(surnameIf) {
- surnameIf = surnameIf
- } else {
- surnameIf = 'Ivanov'
- }
- if (patronymicIf) {
- patronymicIf = patronymicIf
- } else {
- patronymicIf = 'Ivanovich'
- }
-
- alert(`"if else" to add default values:
- ${surnameIf} ${NameIf} ${patronymicIf}`)
-
- break;
-
- case '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')
- }
- break;
-
- case 'currency calc':
- let curr = prompt('type currency: "eur" or "usd"','')
- let transferLog = {
- initial: 'hrn',
- to: '',
- ratios: {
- sold: {
- usd: 0.032,
- eur: 0.037,
- },
- bought: {
- usd: 0.033,
- eur: 0.038
- }
- }
- }
-
- if(curr) {
- // switch(curr.toLowerCase()) {
- // case 'eur':
- // transferLog.to = 'eur'
- // confirm('Sell press "Ok" | Buy press "Cancel"')? transferLog.curr = [transferLog.ratios['sold']['usd'], 'sold'] : transferLog.curr = [transferLog.ratios['bought']['usd'], 'bought']
- // break;
- // case 'usd':
- // transferLog.to = 'usd'
- // confirm('Sell press "Ok" | Buy press "Cancel"')? transferLog.curr = [transferLog.ratios['sold']['eur'], 'sold'] : transferLog.curr = [transferLog.ratios['bought']['eur'], 'bought']
- // break;
- // }
-
- if(curr.toLowerCase() === 'eur') {
- transferLog.to = 'eur'
- confirm('Sell press "Ok" | Buy press "Cancel"')? transferLog.curr = [transferLog.ratios['sold']['usd'], 'sold'] : transferLog.curr = [transferLog.ratios['bought']['usd'], 'bought']
- }
- if(curr.toLowerCase() === 'usd') {
- transferLog.to = 'usd'
- confirm('Sell press "Ok" | Buy press "Cancel"')? transferLog.curr = [transferLog.ratios['sold']['eur'], 'sold'] : transferLog.curr = [transferLog.ratios['bought']['eur'], 'bought']
- }
-
- if(transferLog.to === 'eur' || transferLog.to === 'usd') {
- transferLog.money = prompt('input amount of money to give', '')
-
- if(!+transferLog.money) {
- alert('invalid input')
- } else {
- transferLog.given = Number(transferLog.money)
- if(transferLog.curr[1] === 'sold') {
- transferLog.money = truncateFraction(transferLog.given / transferLog.curr[0])
- transferLog.message = `You've ${transferLog.curr[1]} ${transferLog.given}${transferLog.to} for ${transferLog.money}${transferLog.initial}`
-
- } else if(transferLog.curr[1] === 'bought') {
- transferLog.money = truncateFraction(transferLog.given * transferLog.curr[0])
- transferLog.message = `You've ${transferLog.curr[1]} ${transferLog.money}${transferLog.to} for ${transferLog.given}${transferLog.initial}`
- }
- transferLog.money > 0? alert(transferLog.message) : alert(`Looks like there is too little amount of hrn given to translate to ${transferLog.to}`)
- }
- } else {
- alert('invalid input')
- }
- } else {
- alert('No input.')
- }
- break;
-
- case 'scissors':
- let combos = {
- paper: {
- conter: 'scissors'
- },
- scissors: {
- conter: 'rock'
- },
- rock: {
- conter: 'paper'
- }
- }
-
- let user = prompt('rock, paper, scissors?').toLowerCase()
-
- if(user === 'rock' || user === 'paper' || user === 'scissors') {
- let computer = Math.random()
-
- if(computer >= 0.6) {
- computer = 'scissors'
- } else if(computer <= 0.3) {
- computer = 'paper'
- } else {
- computer = 'rock'
- }
- alert(`computer: ${computer}`)
-
- if(user === computer) {
- alert('TIE')
- } else {
- combos[computer].conter === user ? alert('USER WINS.') : alert('COMPUTER WINS.')
- }
- } else {
- alert('user disqualified! Compuer wins!')
- }
- break;
-
-
- case 'real data':
- let currReal = prompt('type currency: "eur" or "usd"','')
-
- if(currReal && currReal.toLowerCase() === 'eur' || currReal.toLowerCase() === 'usd') {
- currReal = currReal.toLowerCase()
- let sellReal = confirm('Sell press "Ok" | Buy press "Cancel"')
- let operationReal = sellReal? 'sold' : 'bought'
- let givenReal = prompt('input amount of money you give:','')
-
- if(givenReal && !isNaN(givenReal)) {
- givenReal = truncateFraction(Number(givenReal))
-
- fetch(`https://open.er-api.com/v6/latest/${currReal.toUpperCase()}`).then(res => res.json())
- .then(data => {
- let got = sellReal ? truncateFraction(givenReal * data.rates.UAH) : truncateFraction(givenReal / data.rates.UAH)
- if(got > 0) {
- sellReal ?
- alert(`You've ${operationReal} ${givenReal}${currReal} for ${got}hrn`):
- alert(`You've ${operationReal} ${got}${currReal} for ${givenReal}hrn`)
- } else {
- alert(`Looks like there is too little amount of money been given to make such operation`)
- }
- })
- } else {
- alert('invalid input')
- }
-
- } else {
- alert('invalid input')
- }
- break;
-
- case 'black belt':
- let combos2 = {
- paper: {
- conter: 'scissors'
- },
- scissors: {
- conter: 'rock'
- },
- rock: {
- conter: 'paper'
- }
- }
- let user2 = prompt('rock, paper, scissors?').toLowerCase()
- let computer2 = Math.random() >= 0.6 ? 'scissors' : (Math.random() <= 0.3 ? 'paper' : 'rock')
- alert(`computer: ${computer2}`)
-
- user2 === 'rock' || user2 === 'paper' || user2 === 'scissors'? (computer2 === user2? alert('TIE') : combos2[computer2].conter === user2 ? alert('USER WINS.') : alert('COMPUTER WINS.')) : alert('user disqualified! Compuer wins!')
-
- break;
-
- case null:
- loop = false
- break;
-
- default:
- alert('no matches found:(')
- }
- }
|