Skip to content

Commit a6ac80c

Browse files
committed
Code 2 - Class 14 / 4
1 parent cdc934d commit a6ac80c

2 files changed

Lines changed: 229 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
10+
<script src="script.js"></script>
11+
</body>
12+
</html>
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
// ECMA international
2+
3+
// ECMAScript === JavaScript
4+
5+
// Template string
6+
// const fname = "Amin";
7+
// const websiteName = "SpaceX";
8+
// const hello = "Hello" + fname + "Welcome to our new" + websiteName + "!🎉";
9+
10+
// const hello2 = `hello ${fname} welcome to our new ${websiteName} !🎉`;
11+
12+
// console.log(hello);
13+
// console.log(hello2);
14+
15+
// ________________________________________________
16+
17+
// let person = { name: "Sara", age: 25 };
18+
// let { name, age } = person;
19+
// console.log(`${name} is ${age} years old`);
20+
21+
// ________________________________________________
22+
23+
// Spread operator
24+
const animals = {
25+
tiger: 12,
26+
lion: 8,
27+
snake: 2,
28+
owl: 44,
29+
};
30+
31+
// const { tiger, ...rest } = animals;
32+
33+
function objectSpread(p1, p2, p3) {
34+
console.log(p1);
35+
console.log(p2);
36+
console.log(p3);
37+
}
38+
39+
const { tiger, lion, ...rest } = animals;
40+
41+
// objectSpread(tiger, lion, rest);
42+
43+
// ________________________________________________
44+
45+
// Data type (Symbols)
46+
let sym1 = Symbol()
47+
let sym2 = Symbol("Amin");
48+
let sym3 = Symbol("Morteza");
49+
let sym4 = Symbol("Morteza");
50+
51+
// console.log(sym2 === sym3);
52+
// console.log(sym3 === sym4);
53+
// console.log(sym3 === sym3);
54+
55+
// ________________________________________________
56+
57+
// default arguments
58+
59+
function hi(name = "", age = "", pet = "Cat") {
60+
name = "Amin";
61+
age = "19";
62+
return console.log(`Hi ${name} you are ${age} years old and you have a lovely ${pet}`);
63+
}
64+
65+
// hi();
66+
67+
// ________________________________________________
68+
69+
// //Arrow function
70+
// function fa(a, b) {
71+
// return a + b;
72+
// }
73+
74+
// const fa = (a, b) => {
75+
// return a + b;
76+
// };
77+
78+
// const fa = (a, b) => a + b;
79+
80+
// const fa = (a) => a;
81+
82+
// ________________________________________________
83+
84+
// let & const
85+
86+
// const player = "amin";
87+
// let experience = 100;
88+
// let wizard = false;
89+
90+
// if (experience > 90) {
91+
// wizard = true;
92+
// }
93+
94+
// console.log(wizard);
95+
96+
// player = "batman"; ❌
97+
98+
// console.log(player);
99+
100+
// const obj = {
101+
// player: "amin",
102+
// experience: 100,
103+
// wizard: false,
104+
// };
105+
106+
// obj = 5 // ❌
107+
108+
// obj.wizard = true; // ✅
109+
110+
// try {
111+
112+
// } catch {
113+
114+
// }
115+
116+
// catch()
117+
118+
// 1)
119+
function fail() {
120+
try {
121+
console.log("this works")
122+
throw new Error("ops!");
123+
// console.log("this works");
124+
} catch (error) {
125+
// error parameter
126+
console.log("we have made and error", error);
127+
}
128+
}
129+
130+
// fail(); // we have made and error Error: ops!
131+
132+
// ________________________________________________
133+
134+
// 2)
135+
function fail() {
136+
try {
137+
console.log("this works")
138+
} catch (error){ // error parameter
139+
console.log("we have made and error")
140+
}
141+
}
142+
143+
// fail()
144+
145+
// ________________________________________________
146+
147+
// 3)
148+
// function fail() {
149+
// try {
150+
// throw new Error("ops!");
151+
// } catch (error) {
152+
// // error parameter
153+
// console.log("we have made and error", error);
154+
// } finally {
155+
// console.log("this will always run");
156+
// return "returning failed";
157+
// }
158+
// console.log("!!!!!!!! :)");
159+
// }
160+
161+
// fail();
162+
163+
// ________________________________________________
164+
165+
function aminAge(age){
166+
try{
167+
let amin = 19
168+
if(isNaN(amin)){
169+
throw new Error("age is not valid!")
170+
}
171+
console.log("Your age:",amin)
172+
}catch (error){
173+
console.log("error",error)
174+
}
175+
}
176+
177+
// aminAge()
178+
179+
// ________________________________________________
180+
181+
// try {
182+
// // This will throw an error because 'x' is not defined
183+
// console.log(x);
184+
// } catch (error) {
185+
// console.log("An error occurred:", error.message);
186+
// }
187+
188+
// ________________________________________________
189+
190+
async function main() {
191+
try {
192+
await x
193+
await y
194+
} catch (error) {
195+
console.log(error);
196+
}
197+
console.log("hey!");
198+
}
199+
200+
// main()
201+
202+
// ________________________________________________
203+
204+
async function fetchProduct() {
205+
try {
206+
const response = await fetch("https://fakestoreapi.com/products")
207+
if (!response.ok) {
208+
throw new Error("fetching data was unsuccessful!")
209+
}
210+
const data = await response.json();
211+
console.log("Products:", data)
212+
} catch (error) {
213+
console.log("Error:", error.massage)
214+
}
215+
}
216+
217+
fetchProduct()

0 commit comments

Comments
 (0)