// 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 на на Американский формат','') switch(+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; } //switch: if let color = prompt("Введите цвет",""); switch (color){ case "red": document.write("
красный
"); case "black": document.write("
черный
"); break; case "blue": document.write("
синий
"); case "green": document.write("
зеленый
"); break; default: document.write("
Я не понял
"); } if(color === 'red') { document.write("
красный
"); document.write("
черный
"); } else if(color === 'blue') { document.write("
синий
"); document.write("
зеленый
"); } else if(color === 'green') { document.write("
зеленый
"); } else if(color === 'black') { document.write("
черный
"); } else { document.write("
Я не понял
"); } //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}г.`) } //confirm: or this days 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 } } let curr = prompt('type currency: "eur" or "usd"','') let transferLog = { initial: 'hrn', to: '', ratios: { sold: { usd: 0.032, eur: 0.037, setUsd: function(value) { this.usd = value }, setEur: function(value) { this.eur = value } }, bought: { usd: 0.033, eur: 0.038 } } } //currency calc:if if(curr) { // switch(curr.toLocaleLowerCase()) { // 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.toLocaleLowerCase() === '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.toLocaleLowerCase() === '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.') } // scissors let combos = { paper: { conter: 'scissors' }, scissors: { conter: 'rock' }, rock: { conter: 'paper' } } let user = prompt('rock, paper, scissors?').toLocaleLowerCase() 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!') }