$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #151

Which fix removes the bug?

const age: number = parseInt(input);
if (age > 18) grant();
  1. Check the result for NaN
  2. Pass a radix to parseInt
  3. Type age as string too
  4. Use >= instead of >
parseInt returns NaN on bad input, and every comparison with NaN is false.
Play Problem Solving ▸