TheAlgorithms/JavaScript · error · Error
Please provide number greater that 1
Error message
Please provide number greater that 1
What it means
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.
Source
Thrown at Project-Euler/Problem017.js:105
* Validation is performed for input
* Loop is executed to find total word length for given number range
* starting from 1
*
*
* @param {number} number
* @returns {number}
*/
const countNumberWordLength = (number) => {
let count = 0
// Not a number check
if (Number.isNaN(parseInt(number))) {
throw new Error('Invalid input, please provide valid number')
}
// Number should be greater than 1
if (number < 1) {
throw new Error('Please provide number greater that 1')
}
// Loop to calculate word length by calling {@link numberToWord}
for (let i = 1; i <= number; i++) {
count += numberToWordLength(i)
}
// return final count for number word length
return count
}
export { countNumberWordLength }
View on GitHub (pinned to 5c39e87a9a)
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.
Example fix
// before
countNumberWordLength(n) // n could be 0
// after
const num = Number(n)
if (!Number.isInteger(num) || num < 1) throw new RangeError('number must be a positive integer >= 1')
countNumberWordLength(num) Defensive patterns
Strategy: validation
Validate before calling
const n = Number(number)
if (!Number.isInteger(n) || n < 1) {
throw new RangeError('number must be an integer >= 1')
}
countNumberWordLength(n) Type guard
const isPositiveInt = (x) => typeof x === 'number' && Number.isInteger(x) && x >= 1
Prevention
- 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.
When it happens
Trigger: Call `countNumberWordLength(0)`, `countNumberWordLength(-3)`, `countNumberWordLength('0')`. `number = 1` passes and returns the length of 'one'.
Common situations: Off-by-one in upper-bound loops, defaulting a 'count up to N' field to 0, or arithmetic that produced a negative result.
Related errors
- No natural numbers exist below 1
- Fibonacci sequence limit can't be less than 1
- Invalid Input
- Invalid Input
- Dimension must be odd
AI-assisted analysis of TheAlgorithms/JavaScript@5c39e87a9a (2026-08-13).
Data as JSON: /api/errors/df8728f70fcb5720.
Report an issue: GitHub.