forked from truecodersio/JavaScript_Error_Handling
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
27 lines (21 loc) · 572 Bytes
/
app.js
File metadata and controls
27 lines (21 loc) · 572 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// TODO: Enable strict mode
"use strict";
// TODO: Fix the following parameter list
function parseToJSON(data, otherData) {
// TODO: Add a try/catch block to
// attempt to convert 'data' to JSON
try {
return JSON.parse(data);
}
catch(error) {
console.error(error);
return null;
}
// TODO: if an exception is raised
// print the error to the console
// and return null
}
let failData = "<h1>Hello World!</h1>"
let passData = JSON.stringify({ success: true });
console.log(parseToJSON(failData));
console.log(parseToJSON(passData));