Your Submissions
You haven't submitted any code for this challenge yet. Solve the problem by passing all the test cases, and your submissions will appear here.
xxxxxxxxxx
52
function parseJSON(input) {
// if the input is empty or starts with an invalid character, throw an error
if (input === "" || input[0] === "'") {
throw Error();
}
// check if the input is null, an empty object, empty array, or a boolean and return the value from the input
if (input === "null") {
return null;
}
if (input === "{}") {
return {};
}
if (input === "[]") {
return [];
}
if (input === "true") {
return true;
}
if (input === "false") {
return false;
}
//if the input starts with a quote, return the value from inside the quotes
if (input[0] === '"') {
return input.slice(1, -1);
OUTPUT
Results will appear here.