$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #52

What is the correct fix?

function half(s) {
  return parseInt(s) / 2;
}
half('08');
  1. Pass the radix: parseInt(s, 10)
  2. Pass the radix: parseInt(s, 2)
  3. Swap parseInt for parseFloat(s)
  4. Wrap the whole call in String(s)
Always give parseInt a radix; without it the base is implementation-dependent for odd input.
Play Problem Solving ▸