Browse Source

bluBelt && converChange

Vladislav342 2 years ago
parent
commit
8a4d55df24
2 changed files with 240 additions and 0 deletions
  1. 42 0
      HW_JS_1/blueBelt.html
  2. 198 0
      HW_JS_1/convertValuti.html

+ 42 - 0
HW_JS_1/blueBelt.html

@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="utf-8">
+	<title>Blue Belt</title>
+</head>
+<body>
+	<script>
+		function pass(right,wrong){
+			let login=prompt('','');
+			let pass=prompt('','');
+
+			if(this.logIn==login && this.password==pass){
+				right();
+			} 
+			else{
+				wrong();
+			} 
+		}
+
+		let obj={
+			logIn:'Ivan',
+			password:'hello',
+			right:function(){
+				let div=document.createElement('div');
+				div.style.backgroundColor='green';
+				div.innerHTML='Congratulations !';
+				document.body.append(div);
+			},
+			wrong:function(){
+				let div=document.createElement('div');
+				div.style.backgroundColor='red';
+				div.innerHTML='Something Wrong !';
+				document.body.append(div);
+			}
+		};
+
+		let g=pass.bind(obj);
+		g(()=>obj.right(),()=>obj.wrong());
+	</script>
+</body>
+</html>

+ 198 - 0
HW_JS_1/convertValuti.html

@@ -0,0 +1,198 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="utf-8">
+	<title>convert</title>
+</head>
+<body>
+
+	<input type="input" name="convert" id="convert">
+   	<p><b></b></p>
+   	<div id="params">
+   		<input type="checkbox" name="option1" value="a1" id="i1">UAH
+   		<input type="checkbox" name="option2" value="a2" id="i2">USD
+   		<input type="checkbox" name="option3" value="a3" id="i3">CNY
+   		<input type="checkbox" name="option4" value="a4" id="i4">CHF
+   		<input type="checkbox" name="option5" value="a5" id='i5'>EUR
+   	</div>
+
+	<p><input type="button" name="btn" id="btn" value="Press" onclick="conv()"></p>
+
+	<div id="hid">
+		
+	</div>
+
+
+	<script>
+		function conv(){
+			if(i1.checked==true){
+				while (hid.hasChildNodes()) {
+    				hid.removeChild(hid.firstChild);
+				}
+				fetch('https://open.er-api.com/v6/latest/UAH')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='USD: '+'$'+data.rates.USD*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/UAH')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='CNY: '+data.rates.CNY*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/UAH')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='CHF: '+data.rates.CHF*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/UAH')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='EUR: '+Number(data.rates.EUR).toFixed(3)*convert.value;
+						hid.append(p);
+					});
+			}
+			if(i2.checked==true){
+				while (hid.hasChildNodes()) {
+    				hid.removeChild(hid.firstChild);
+				}
+				fetch('https://open.er-api.com/v6/latest/USD')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='UAH: '+'$'+data.rates.UAH*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/USD')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='CNY: '+data.rates.CNY*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/USD')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='CHF: '+data.rates.CHF*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/USD')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='EUR: '+Number(data.rates.EUR).toFixed(3)*convert.value;
+						hid.append(p);
+					});
+			}
+			if(i3.checked==true){
+				while (hid.hasChildNodes()) {
+    				hid.removeChild(hid.firstChild);
+				}
+				fetch('https://open.er-api.com/v6/latest/CNY')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='UAH: '+'$'+data.rates.UAH*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/CNY')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='USD: '+data.rates.USD*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/CNY')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='CHF: '+data.rates.CHF*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/CNY')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='EUR: '+Number(data.rates.EUR).toFixed(3)*convert.value;
+						hid.append(p);
+					});
+			}
+			if(i4.checked==true){
+				while (hid.hasChildNodes()) {
+    				hid.removeChild(hid.firstChild);
+				}
+				fetch('https://open.er-api.com/v6/latest/CHF')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='UAH: '+'$'+data.rates.UAH*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/CHF')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='CNY: '+data.rates.CNY*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/CHF')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='USD: '+data.rates.USD*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/CHF')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='EUR: '+Number(data.rates.EUR).toFixed(3)*convert.value;
+						hid.append(p);
+					});
+			}
+			if(i5.checked==true){
+				while (hid.hasChildNodes()) {
+    				hid.removeChild(hid.firstChild);
+				}
+				fetch('https://open.er-api.com/v6/latest/EUR')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='UAH: '+'$'+data.rates.UAH*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/EUR')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='CNY: '+data.rates.CNY*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/EUR')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='CHF: '+data.rates.CHF*convert.value;
+						hid.append(p);
+					});
+				fetch('https://open.er-api.com/v6/latest/EUR')
+					.then(r=>r.json())
+					.then(data=>{
+						let p=document.createElement('p');
+						p.innerHTML='USD: '+Number(data.rates.USD).toFixed(3)*convert.value;
+						hid.append(p);
+					});
+			}
+		}
+
+		//let urls=['UAH','USD','CNY','CHF','EUR'];
+	</script>
+</body>
+</html>