Do not trust the parsed value

Parsing JSON does not establish that the result is a number.

your task

Keep seatCount’s parameter and return types. Treat the parsed value as unknown. Return a number for numbers and text that converts to a number. For other parsed values, throw “Seats must be a number”.

The service can send the seat count as a JSON number or as text. The starter passes the type check but returns text for "4". It also accepts a boolean as a seat count.

Starter code
or press Ctrl EnterNot run yet

type check

Not run yetcount.ts

Expected result: no type errors.

cases

Not run yetA number, including zero

Expected output

14 number
20 number
See the input and the code for this case
function show(text) {
  try {
    const seats = seatCount(text);
    console.log(seats + " " + typeof seats);
  } catch (error) {
    console.log("error: " + error.message);
  }
}
show("4");
show("0");
Not run yetA number sent as text

Expected output

14 number
See the input and the code for this case
function show(text) {
  try {
    const seats = seatCount(text);
    console.log(seats + " " + typeof seats);
  } catch (error) {
    console.log("error: " + error.message);
  }
}
show('"4"');
Not run yetA boolean or nonnumeric text

Expected output

1error: Seats must be a number
2error: Seats must be a number
See the input and the code for this case
function show(text) {
  try {
    const seats = seatCount(text);
    console.log(seats + " " + typeof seats);
  } catch (error) {
    console.log("error: " + error.message);
  }
}
show("true");
show('"four"');