Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion quiz/exception.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ <h1>Error Handling with Array Map</h1>
// 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
Expand Down
2 changes: 1 addition & 1 deletion quiz/scripts/map-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions quiz/scripts/stack-q1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
5 changes: 2 additions & 3 deletions scripts/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ export function add(a, b) {

// Function to multiply two numbers
export function multiply(a, b) {
return a * b;
}

return a * b;
}