let task = prompt('enter task name').toLowerCase();
switch (task) {
case 'switch: sizes':
let size = +prompt('введите размер обуви дял конвертации в UK')
switch (size) {
case 35:
alert(3.5);
break;
case 36:
alert(4);
break;
case 37:
alert(5);
break;
case 38:
alert(6);
break;
case 39:
alert(6.5);
break;
case 40:
alert(7);
break;
default:
alert('something went wrong')
}
break;
case 'switch: if':
let color = prompt("Введите цвет","");
if(color === "red") {
document.write("
красный
")
} else if(color === "black") {
document.write("черный
")
} else if(color === "blue") {
document.write("синий
")
} else if(color === "green") {
document.write("зеленый
")
} else {
document.write("Я не понял
")
}
break;
case 'prompt: or':
let age1 = prompt('how old are you?');
if(age1 === '' || age1 === null) {
alert('something is wrong...')
} else {
alert(`you were born in ${2022 - age1}`)
}
break;
case 'confirm: or this days':
let question1 = confirm('Шоппинг?') || alert(' Ты - бяка!');
break;
case 'confirm: if this days':
let question2 = confirm('Шоппинг?');
if(!question2) {
alert(' Ты - бяка!')
}
break;
case 'triple prompt':
let surname = prompt('Enter surname')
let name = prompt('Enter name')
let patronymic = prompt('Enter patronymic')
alert(`${surname} ${name} ${patronymic}`)
break;
case 'default: or':
let enteredName = prompt('enter your name');
let enteredSurname = prompt('enter your surname');
enteredName = enteredName || 'Ivan';
enteredSurname = enteredSurname || 'Ivanov';
break;
case 'default: if':
let enteredName2 = prompt('enter your name');
let enteredSurname2 = prompt('enter your surname');
if(!enteredSurname2) {
enteredSurname2 = 'Ivanov'
}
if(!enteredName2) {
enteredName2 = 'Ivan'
}
break;
case 'login and password':
const adminName = 'admin';
const adminPassword = 'qwerty';
let login = prompt('Login: ');
if(adminName === login) {
let password = prompt('Password: ');
if(adminPassword === password) {
alert('Success!')
} else {
alert('password is incorrect')
}
} else {
alert('login is incorrect')
}
break;
case 'currency calc':
let currency1 = prompt('USD or EUR?')
let rate1;
switch (currency1) {
case 'usd':
rate1 = 34.67
break;
case 'eur':
rate1 = 37.38
break;
default:
rate1 = 0;
}
let uah = +prompt('enter UAH to convert');
alert(`${(uah / rate1).toFixed(2)} ${currency1}`)
break;
case 'currency calc: improved':
let currency2 = prompt('USD or EUR?').toLowerCase();
let rate2;
switch (currency2) {
case 'usd':
rate2 = 34.67
break;
case 'eur':
rate2 = 37.38
break;
default:
rate2 = 0;
}
let uah1 = +prompt('enter UAH to convert');
alert(`${(uah1 / rate2).toFixed(2)} ${currency2}`)
break;
case 'currency calc: two rates':
let currency3 = prompt('Do you want to use USD or EUR?').toLowerCase()
let rate3;
let buyRate1 = confirm('Do you want to buy currency?')
switch (currency3) {
case 'usd':
buyRate1 ? rate3 = 36.28 : rate3 = 34.67
break;
case 'eur':
buyRate1 ? rate3 = 41.77 : rate3 = 37.38
break;
default:
alert('error');
}
let uah2 = +prompt('enter UAH to convert');
alert(`${(uah2 / rate3).toFixed(2)} ${currency3}`)
break;
case 'currency calc: if':
let currency4 = prompt('Do you want to use USD or EUR?').toLowerCase()
if(currency4 === 'usd' || currency4 === 'eur') {
let uah4 = +prompt('enter UAH to convert');
let rate4;
let buyRate2 = confirm('Do you want to buy currency?')
if (currency4 === 'usd') {
buyRate2 ? rate4 = 36.28 : rate4 = 34.67
} else if (currency4 === 'eur') {
buyRate2 ? rate4 = 41.77 : rate4 = 37.38
} else {
alert('error')
}
alert(`${(uah4 / rate4).toFixed(2)} ${currency4}`)
}
break;
case 'scissors':
let usersTurn = prompt('Rock, paper or scissors?').toLowerCase();
let turns = ['rock', 'paper', 'scissors'];
const randomIndex = Math.floor(Math.random() * 3)
let computersTurn = turns[randomIndex]
console.log(computersTurn)
if(usersTurn === computersTurn) {
alert('It\'s a tie!')
} else if(usersTurn === 'paper' && computersTurn === 'scissors') {
alert('computer won');
} else if(usersTurn === 'scissors' && computersTurn === 'rock') {
alert('computer won');
} else if(usersTurn === 'rock' && computersTurn === 'paper') {
alert('computer won')
} else if(computersTurn === 'paper' && usersTurn === 'scissors') {
alert('you won');
} else if(computersTurn === 'scissors' && usersTurn === 'rock') {
alert('you won');
} else if(computersTurn === 'rock' && usersTurn === 'paper') {
alert('you won')
} else {
alert('error')
}
break;
case 'задание на синий пояс':
let ratios = {
usdToBuy: 36.28,
eurToBuy: 41.77,
usdToSell: 34.67,
eurToSell: 37.38
}
let currency5 = prompt('Do you want to use USD or EUR?').toLowerCase()
if(currency5 === 'usd' || currency5 === 'eur') {
let rate;
let uah = +prompt('enter UAH to convert');
let buyRate = confirm('Do you want to buy currency?')
if (currency5 === 'usd') {
rate = buyRate ? ratios["usdToBuy"] : ratios["usdToSell"]
} else if (currency5 === 'eur') {
rate = buyRate ? ratios["eurToBuy"] : ratios["eurToSell"]
} else {
alert('error')
}
alert(`${(uah / rate).toFixed(2)} ${currency5}`)
}
break;
case 'real data':
let currency = prompt('Enter the currency name to convert (e.g. USD)').toUpperCase()
let uah3 = +prompt('enter UAH to convert');
fetch('https://open.er-api.com/v6/latest/' + currency)
.then(res => res.json())
.then(data => {
alert(`${(uah3 / data.rates.UAH).toFixed(2)} ${currency}`)
})
break;
case 'задание на черный пояс':
let usersTurn1 = prompt('Rock, paper or scissors?').toLowerCase();
let turns1 = ['rock', 'paper', 'scissors'];
const randomIndex1 = Math.floor(Math.random() * 3)
let computersTurn1 = turns1[randomIndex1]
console.log(computersTurn1)
let compWin = usersTurn1 === 'paper' && computersTurn1 === 'scissors' || usersTurn1 === 'scissors' && computersTurn1 === 'rock' || usersTurn1 === 'rock' && computersTurn1 === 'paper';
let userWin = computersTurn1 === 'paper' && usersTurn1 === 'scissors' || computersTurn1 === 'scissors' && usersTurn1 === 'rock' || computersTurn1 === 'rock' && usersTurn1 === 'paper';
let tie = usersTurn1 === computersTurn1 && alert('It\'s a tie!')
let victory = compWin && alert('computer won') || userWin && alert('you won');
break;
};