{"record":{"id":"df8728f70fcb5720","repo":"TheAlgorithms/JavaScript","slug":"please-provide-number-greater-that-1","errorCode":null,"errorMessage":"Please provide number greater that 1","messagePattern":"Please provide number greater that 1","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"Project-Euler/Problem017.js","lineNumber":105,"sourceCode":" * Validation is performed for input\n * Loop is executed to find total word length for given number range\n * starting from 1\n *\n *\n * @param {number} number\n * @returns {number}\n */\nconst countNumberWordLength = (number) => {\n  let count = 0\n\n  // Not a number check\n  if (Number.isNaN(parseInt(number))) {\n    throw new Error('Invalid input, please provide valid number')\n  }\n\n  // Number should be greater than 1\n  if (number < 1) {\n    throw new Error('Please provide number greater that 1')\n  }\n\n  // Loop to calculate word length by calling {@link numberToWord}\n  for (let i = 1; i <= number; i++) {\n    count += numberToWordLength(i)\n  }\n\n  // return final count for number word length\n  return count\n}\n\nexport { countNumberWordLength }\n","sourceCodeStart":87,"sourceCodeEnd":118,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/Project-Euler/Problem017.js#L87-L118","documentation":"Thrown by `countNumberWordLength(number)` (Project Euler #17) when `number < 1`, AFTER the parseInt check has passed. Note the message contains a typo ('greater that 1' instead of 'greater than 1') and the boundary is exclusive: `number = 1` is allowed. Because the prior parseInt check is loose, strings that parse to integers below 1 (e.g. '0') reach this throw.","triggerScenarios":"Call `countNumberWordLength(0)`, `countNumberWordLength(-3)`, `countNumberWordLength('0')`. `number = 1` passes and returns the length of 'one'.","commonSituations":"Off-by-one in upper-bound loops, defaulting a 'count up to N' field to 0, or arithmetic that produced a negative result.","solutions":["Validate `number >= 1` (decide explicitly whether 1 is valid for your use case).","Coerce strictly with `Number(...)` and `Number.isInteger` rather than relying on parseInt.","Note the message typo if you surface it to users - reword before display."],"exampleFix":"// before\ncountNumberWordLength(n) // n could be 0\n\n// after\nconst num = Number(n)\nif (!Number.isInteger(num) || num < 1) throw new RangeError('number must be a positive integer >= 1')\ncountNumberWordLength(num)","handlingStrategy":"validation","validationCode":"const n = Number(number)\nif (!Number.isInteger(n) || n < 1) {\n  throw new RangeError('number must be an integer >= 1')\n}\ncountNumberWordLength(n)","typeGuard":"const isPositiveInt = (x) => typeof x === 'number' && Number.isInteger(x) && x >= 1","tryCatchPattern":null,"preventionTips":["Coerce strictly with Number() + Number.isInteger rather than parseInt.","Decide whether 1 is valid for your use case and validate accordingly.","Reword the typo'd library message before showing it to end users."],"tags":["range-validation","project-euler","typo-message","boundary"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}