Skip to content

Commit 2fc52e9

Browse files
committed
Added exercises for 02 and 04
1 parent 68c3aa5 commit 2fc52e9

11 files changed

+81
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const searchParams = new URLSearchParams(window.location.search);
2+
3+
const id = searchParams.get("id");
4+
5+
console.log(id.toUpperCase());
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const searchParams = new URLSearchParams(window.location.search);
2+
3+
const id = searchParams.get("id");
4+
5+
console.log(id?.toUpperCase());
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const searchParams = new URLSearchParams(window.location.search);
2+
3+
const id = searchParams.get("id");
4+
5+
console.log(id!.toUpperCase());
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const searchParams = new URLSearchParams(window.location.search);
2+
3+
const id = searchParams.get("id");
4+
5+
if (id) {
6+
console.log(id.toUpperCase());
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const searchParams = new URLSearchParams(window.location.search);
2+
3+
const id = searchParams.get("id");
4+
5+
if (typeof id === "string") {
6+
console.log(id.toUpperCase());
7+
}

src/002-possibly-null-or-undefined.solution.ts

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const somethingDangerous = () => {
2+
if (Math.random() > 0.5) {
3+
throw new Error("Oh dear!");
4+
}
5+
};
6+
7+
try {
8+
somethingDangerous();
9+
} catch (error) {
10+
console.log(error.message);
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const somethingDangerous = () => {
2+
if (Math.random() > 0.5) {
3+
throw new Error("Oh dear!");
4+
}
5+
};
6+
7+
try {
8+
somethingDangerous();
9+
} catch (error) {
10+
console.log((error as Error).message);
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const somethingDangerous = () => {
2+
if (Math.random() > 0.5) {
3+
throw new Error("Oh dear!");
4+
}
5+
};
6+
7+
try {
8+
somethingDangerous();
9+
} catch (error) {
10+
if (typeof error === "object" && error && "message" in error) {
11+
console.log(error.message);
12+
} else {
13+
throw error;
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const somethingDangerous = () => {
2+
if (Math.random() > 0.5) {
3+
throw new Error("Oh dear!");
4+
}
5+
};
6+
7+
try {
8+
somethingDangerous();
9+
} catch (error) {
10+
if (error instanceof Error) {
11+
console.log(error.message);
12+
} else {
13+
throw error;
14+
}
15+
}

0 commit comments

Comments
 (0)