Skip to content
Open

DZ #2

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 7-converter/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Совершенно не понял как сделать это, пытался прогуглить, но там уже более сложные примеры и варианты решения подобной задачи. Направьте, пожалуйста, какое решение применить?

function summ (amount, sourceCurrency, targetCurrencyUSD, targetCurrencyEUR ) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 3 - параметра (сумма, из какой валюты, в какую валюту)
  2. Далее внутри функции у тебя должны быть коэффициенты для перевода валюты из одной в другую
switch (initialCurrency) {
		case 'RUB': switch (targetCurrency) {
			case 'USD': return amount / 89.7619;
			case 'EUR': return amount / 97.9126;
			case 'GBP': return amount / 113.6027;
			default: return null;
		}
		case 'USD': switch (targetCurrency) {
			case 'RUB': return amount * 89.7619;
			case 'EUR': return amount * 0.9168;
			case 'GBP': return amount * 0.7901;
			default: return null;
		}
		case 'EUR': switch (targetCurrency) {
			case 'RUB': return amount * 97.9126;
			case 'USD': return amount * 1.0908;
			case 'GBP': return amount * 0.8619;
			default: return null;
		}
		case 'GBP': switch (targetCurrency) {
			case 'RUB': return amount * 113.6027;
			case 'USD': return amount * 1.2656;
			case 'EUR': return amount * 1.1602;
			default: return null;
		}
		default:
			return null;
	}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Теперь понял, благодарю!

let USD = 90;
let RUB = 1;
let EUR = 96;
let targetUSD = USD > RUB;
let targetEUR = EUR > RUB;

switch(true) {
case targetUSD:
return (amount / USD) + targetCurrencyUSD;

case targetEUR:
return (amount / EUR) + targetCurrencyEUR;

default:
return null || 0;
}
};

console.log(summ(1000, ` руб.`, `$`, `€`));
12 changes: 12 additions & 0 deletions 7-converter/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./app.js"></script>
</head>
<body>

</body>
</html>
17 changes: 17 additions & 0 deletions 8-crypto/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const password = ['s','s','a','p','d','o','r','w'];
const fullPassword = password.join('');
console.log(fullPassword);


// Как в массиве сделать перестановку символов местами без их удаления и вернуть потом обратно?
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ну можешь циклом for бежать по массиву) метод сплайс мутирует твой массив исходный, из за этого у тебя баги

function passEncryptor() {
password [2] = password.splice(0, 1, password[3])[0];
console.log(password);

};
passEncryptor();

function passCheck () {
console.log(fullPassword.includes('ssapdorw'|| 'password'));
};
passCheck();
12 changes: 12 additions & 0 deletions 8-crypto/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./app.js"></script>
</head>
<body>

</body>
</html>
35 changes: 35 additions & 0 deletions 9-sort-loops/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const arr = [1, 40, -50, -20, -10, 5, 0, 100];

function sort(arrayOfSort) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вообще не верно решил))) в чем смысл программирования? в автоматизации) а теперь представь что у тебя миллион элментов в массиве?)
https://proglib.io/p/bubble-sort - почитай про алгоритм сортировки)

for (const element of arrayOfSort) {
switch (true) {
case arr[0] > arr [1]:
arr1 = arr[1];
arr[1] = arr[0];
arr[0] = arr1;
case arr[1] > arr [2]:
arr2 = arr[2];
arr[2] = arr[1];
arr[1] = arr2;
case arr[2] > arr [3]:
arr3 = arr[3];
arr[3] = arr[2];
arr[2] = arr3;
case arr[3] > arr [4]:
arr4 = arr[4];
arr[4] = arr[3];
arr[3] = arr4;
case arr[4] > arr [5]:
arr5 = arr[5];
arr[5] = arr[4];
arr[4] = arr5;
case arr[5] > arr [6]:
arr6 = arr[6];
arr[6] = arr[5];
arr[5] = arr6;
};
};
return arr;
};

console.log(sort(arr))
12 changes: 12 additions & 0 deletions 9-sort-loops/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./app.js"></script>
</head>
<body>

</body>
</html>