diff --git a/quiz/exception.html b/quiz/exception.html
index c154b213..c34055e2 100644
--- a/quiz/exception.html
+++ b/quiz/exception.html
@@ -24,7 +24,16 @@
Error Handling with Array Map
// Using map to calculate the square root of each number
// Use Math.sqrt(number) to calculate sq root
const squareRoots = numbers.map(number => {
- return 0
+ try {
+ if(isNaN(number)) throw `${number} is not a valid number`
+ if(number < 0) throw `${number} is negative`
+ return Math.sqrt(number)
+ }
+
+ catch(err) {
+ console.log(`Error: ${err}`)
+ return NaN
+ }
});
// Displaying the original and transformed arrays
diff --git a/quiz/scripts/map-deep.js b/quiz/scripts/map-deep.js
index e97665e5..d43455c6 100644
--- a/quiz/scripts/map-deep.js
+++ b/quiz/scripts/map-deep.js
@@ -6,7 +6,7 @@ const originalMatrix = [
];
const newMatrix = originalMatrix.map((row) => {
- return row.sort();
+ return Array.from(row).sort();
});
// Modifying the original matrix (changing the last element of the first row)
diff --git a/quiz/scripts/stack-q1.js b/quiz/scripts/stack-q1.js
index 0d719223..72aa78ea 100644
--- a/quiz/scripts/stack-q1.js
+++ b/quiz/scripts/stack-q1.js
@@ -16,6 +16,14 @@ class PStackImpl extends PStack {
super();
}
+ get persons() {
+ return this._persons;
+ }
+
+ set persons(persons) {
+ this._persons = persons;
+ }
+
push(p) {
return this._persons.push(p)
}
diff --git a/scripts/exception.js b/scripts/exception.js
index c5e554fa..98582256 100644
--- a/scripts/exception.js
+++ b/scripts/exception.js
@@ -6,7 +6,7 @@ window.onload = function() {
let x = document.getElementById("demo").value;
try {
if(x == "") throw 'empty';
- if(isNan(x)) throw 'not a number';
+ if(isNaN(x)) throw 'not a number';
x = Number(x);
if(x < 5) throw 'too low';
if(x > 10) throw 'too high';
diff --git a/scripts/math.js b/scripts/math.js
index 75ad0f71..64d0f6c7 100644
--- a/scripts/math.js
+++ b/scripts/math.js
@@ -7,6 +7,5 @@ export function add(a, b) {
// Function to multiply two numbers
export function multiply(a, b) {
-return a * b;
-}
-
\ No newline at end of file
+ return a * b;
+}
\ No newline at end of file