let exersice = prompt("Chose exersice: \n switch: sizes - 1 \n switch: if - 2 \n prompt: or - 3 \n confirm: or this days - 4 \n confirm: if this days - 5\n triple prompt + default: or - 6 \n default: if - 7 \n login and password - 8 \n currency calc + currency calc: improved + currency calc: two rates - 9\n corrency calc: if - 10 \n scissors - 11 \n blue belt - 12 \n black belt - 13" )
switch (exersice){
case "1": searchSize(); break;
case "2": color(); break;
case "3": year(); break;
case "4": Shopping(); break;
case "5": ShoppingIf(); break;
case "6": yourName(); break;
case "7": yourNameSecond(); break;
case "8": Log(); break;
case "9": currencyCalc(); break;
case "10": currencyCalc2(); break;
case "11": scissors(); break;
case "12": blueBelt(); break;
case "13": blackBelt(); break;
default: alert("Error. Try again")
}
//////
////switch: sizes 1
function searchSize (styleWear, firstMassive, firstSize) {
sizeWear = {
russia: [40, 42, 44, 46, 48, 50, 52, 54],
USA: ["S", "M", "M", "L", "L", "XL", "XL", "XXL"]
}
womanSize = {
russia: [42 ,44, 46, 48, 50, 52, 54, 56],
USA: ["XXS", "XS", "S", "M", "L", "XL", "XXL", "XXXL"]
}
sizeStockings = {
russia: [21, 21, 23, 23, 25, 25, 27],
USA: [8, 8.5, 9, 9.5, 10, 10.5, 11]
}
styleWear = prompt("What size chart do you need?(dress/outerwear/pants - 1, lingerie - 2, tights/stockings - 3", "");
switch (styleWear) {
case "1": styleWear = sizeWear, firstMassive = sizeWear.russia; break;
case "2": styleWear = womanSize, firstMassive = womanSize.russia; break;
case "3": styleWear = sizeStockings, firstMassive = sizeStockings.russia; break;
default: alert ("Error. Please try again");
return
}
firstSize = +prompt("Please give me your size in Russia/Urkaine style");
firstSize = firstMassive.indexOf(firstSize)
if (firstSize == -1) {
return alert("Error. Please check your data")
}
alert ("Your size in USA chart is " + styleWear.USA[firstSize])
}
// searchSize()
///////
//////
////switch: if 2
function color() {
let color = prompt("Введите цвет","");
if (color === "red") {
document.write("
красный
")
document.write("черный
")
} else if (color === "black") {
document.write("черный
")
} else if (color === "blue") {
document.write("синий
")
document.write("зеленый
")
} else if ( color === "green") {
document.write("зеленый
")
}
else {
document.write("Я не понял
")
}
}
// color()
////////
///////
///prompt: or 3
function year (yearBorn) {
var today = new Date();
var year = today.getFullYear();
yearBorn = + prompt ("How old are you?");
if (yearBorn == null || yearBorn == undefined || isNaN(yearBorn) || yearBorn == false) {
return alert("Error. Please try again")
} else {
yearBorn = year - yearBorn;
return alert ("The year when you're born is " + yearBorn)
}
}
// year()
////////
/////
//confirm: or this days 4
function Shopping() {
(confirm ("Шопинг?")) ? alert("Уиии") : alert("Ты - бяка")
}
// Shopping()
//////
///////
//confirm: if this days 5
function ShoppingIf (answer) {
answer = confirm("Шопинг?")
if (answer === false) {
return alert("ты-бяка")
} else {
return alert ("Уиии")
}
}
// ShoppingIf()
////////
////////
//triple prompt
//default: or 6
function yourName (surname, name, yourFather) {
surname = prompt ("Напишите, пожалуйста, вашу фамилию")
surname = surname ? surname : "Хренова"
name = prompt("Напишите, пожалуйста, как вас зовут.")
name = name ? name : "Гадя"
yourFather = prompt ("Напишите, пожалуйста, ваше отчество")
yourFather = yourFather ? yourFather : "Петрович"
return alert ("Здравствуйте, " + name + " " + yourFather + " " + surname)
}
// yourName()
////////
/////////
//defaut if 7
function yourNameSecond (surname, name, yourFather) {
question1 = prompt ("Напишите, пожалуйста, вашу фамилию")
if (question1 === null || question1 === "") {
surname = "Хренова"
} else { surname = question1}
question2 = prompt("Напишите, пожалуйста, как вас зовут.")
if (question2 === null || question2 === "") {
name = "Гадя"
} else { name = question2 }
question3 = prompt ("Напишите, пожалуйста, ваше отчество")
if (question3 === null || question3 === "") {
yourFather = "Петрович"
} else { yourFather = question3 }
return alert ("Здравствуйте, " + name + " " + yourFather + " " + surname)
}
// yourNameSecond()
//////////
////////
//login and password 8
function Log (yourLog, yourPass) {
let login = "admin";
let password = "qwerty";
yourLog = prompt ("Please write correct login")
if (yourLog === login){
yourPass = prompt ("Please write correct password")
if (yourPass === password) {
alert ("Congratulations! You're in.")
} else {
alert ("Error. The password is wrong. Please try again")
}
} else {
return alert ("Error. The login is wrong. Please try again")
}
}
// Log()
//////////
//////////
///currency calc
////currency calc: improved
////currency calc: two rates 9
function currencyCalc (yourChoise, yourCount, result) {
let usd = [28.31, 28.39];
let eur = [33, 33.44];
yourChoise = prompt("Please chose usd or eur.").toLowerCase();
switch (yourChoise) {
case "usd":yourChoise = usd; break;
case "eur":yourChoise = eur; break;
default: alert ("Error. Please try again");
return
}
confirm ("If you want to buy click on 'ok' and on 'cancel' if want to sell") ? yourChoise = yourChoise[0] : yourChoise = yourChoise[1];
yourCount = prompt("How much?");
result = yourCount * yourChoise;
(isNaN(result) ? alert ("Error. Please check your data") : alert ("Your result is " + result))
}
// currencyCalc()
/////////
///////
//currency calc: if 10
function currencyCalc2 (yourChoise, yourCount, BuySell, result) {
let usd = [28.31, 28.39];
let eur = [33, 33.44];
yourChoise = prompt("Please chose usd or eur.").toLowerCase();
if (yourChoise == "usd") {
yourChoise = usd
} else if ( yourChoise == "eur") {
yourChoise = eur
} else {
return alert("Error. Please try again")
}
BuySell = confirm ("If you want to buy click on 'ok' and on 'cancel' if want to sell")
if (BuySell === true) {
yourChoise = yourChoise[0]
} else {
yourChoise = yourChoise[1]
}
yourCount = prompt("How much?");
if (isNaN(yourCount)) {
return alert ("Error. Please cheack your data")
} else {
result = yourCount * yourChoise;
return alert ("Your result is " + result)
}
}
// currencyCalc2()
////////
///////
//scissors 11
function scissors (yourMove, myMove){
let tools = ["rock", "scissors", "paper"];
yourMove = prompt("Your move. Chose rock, scissors or paper").toLowerCase();
myMove = tools[Math.floor(Math.random() * tools.length)];
if (yourMove === myMove) {
return alert("Dead heat")
} else if (yourMove == "rock"&& myMove == "scissors" || yourMove == "scissors"&& myMove == "paper" || yourMove == "paper"&& myMove == "rock" ) {
return alert ("Congratulations. You're win")
} else {
return alert ("Sorry. You're lose")
}
}
// scissors()
/////////
//////
///Задание на синий пояс 12
function blueBelt() {
fetch('https://api.exchangeratesapi.io/latest')
.then(res => res.json())
.then(d => {
let yourChoisefirst = prompt("What do you want yo sell?").toUpperCase();
(yourChoisefirst === "EUR") ? yourChoisefirst = 1 : yourChoisefirst = (1 / d.rates[yourChoisefirst]);
let yourChoisesecond = prompt("What do you want to buy?").toUpperCase();
(yourChoisesecond === "EUR") ? yourChoisesecond = 1 : yourChoisesecond = (1 / d.rates[yourChoisesecond]);
let count = prompt("How much?");
let howMuch = (yourChoisefirst / yourChoisesecond * count).toFixed(2);
if (isNaN(howMuch)) {
return alert ("Error. Please check your data")
} else {
return alert(howMuch)
}
})
}
// blueBelt()
////
//////
///Черный пояс 13
function blackBelt (yourMove, myMove){
let tools = ["rock", "scissors", "paper"];
yourMove = prompt("Your move. Chose rock, scissors or paper").toLowerCase();
myMove = tools[Math.floor(Math.random() * tools.length)];
(yourMove === "rock" || yourMove === "paper" || yourMove === "scissors") ? ((yourMove === myMove) ? alert ("Dead heat") : (yourMove == "rock"&& myMove == "scissors" || yourMove == "scissors"&& myMove == "paper" || yourMove == "paper"&& myMove == "rock" ) ? alert("You're win") : alert ("You're lose")) : alert ("Error. Try again")
}
// blackBelt()
//////