{"record":{"id":"e464fa7e82a6b650","repo":"TheAlgorithms/JavaScript","slug":"arguments-are-not-all-numbers","errorCode":null,"errorMessage":"Arguments are not all numbers.","messagePattern":"Arguments are not all numbers\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Maths/ZellersCongruenceAlgorithm.js","lineNumber":8,"sourceCode":"// Zeller's Congruence Algorithm finds the day of the week from the Gregorian Date. Wikipedia: https://en.wikipedia.org/wiki/Zeller%27s_congruence\nexport const zellersCongruenceAlgorithm = (day, month, year) => {\n  if (\n    typeof day !== 'number' ||\n    typeof month !== 'number' ||\n    typeof year !== 'number'\n  ) {\n    throw new TypeError('Arguments are not all numbers.')\n  }\n  const q = day\n  let m = month\n  let y = year\n  if (month < 3) {\n    m += 12\n    y -= 1\n  }\n  day =\n    (q +\n      Math.floor((26 * (m + 1)) / 10) +\n      (y % 100) +\n      Math.floor((y % 100) / 4) +\n      Math.floor(Math.floor(y / 100) / 4) +\n      5 * Math.floor(y / 100)) %\n    7\n  const days = [\n    'Saturday',","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/Maths/ZellersCongruenceAlgorithm.js#L1-L26","documentation":"Thrown by `zellersCongruenceAlgorithm(day, month, year)` when any of the three arguments fails `typeof === 'number'`. The Gregorian-date formula uses arithmetic on all three, so non-numbers break it. The check is type-only - NaN passes and yields garbage.","triggerScenarios":"Call `zellersCongruenceAlgorithm('1', 1, 2020)`, `zellersCongruenceAlgorithm(1, 'Jan', 2020)`, `zellersCongruenceAlgorithm(1, 1, null)`, or any case where a Date component is stringified.","commonSituations":"Date components read from URL params, CSV cells, or `Date` parts passed as strings; mixing the function with `moment.format('M')` (string) outputs.","solutions":["Coerce all three arguments with `Number(...)` and verify each is a finite integer.","When reading from a Date object, use `.getDate()`, `.getMonth() + 1`, `.getFullYear()` (all numbers).","Validate range (1-31 day, 1-12 month, positive year) in addition to type."],"exampleFix":"// before\nzellersCongruenceAlgorithm(req.query.day, req.query.month, req.query.year)\n\n// after\nconst [d, m, y] = [req.query.day, req.query.month, req.query.year].map(Number)\nif (![d, m, y].every((v) => Number.isInteger(v))) throw new TypeError('all date parts must be integers')\nzellersCongruenceAlgorithm(d, m, y)","handlingStrategy":"type-guard","validationCode":"const [d, m, y] = [day, month, year].map(Number)\nif (![d, m, y].every((v) => typeof v === 'number' && Number.isInteger(v))) {\n  throw new TypeError('day, month, year must all be integers')\n}\nzellersCongruenceAlgorithm(d, m, y)","typeGuard":"const isInt = (x) => typeof x === 'number' && Number.isInteger(x)","tryCatchPattern":null,"preventionTips":["Use Date methods (getDate, getMonth+1, getFullYear) which return numbers.","Coerce URL/query params with Number() before forwarding.","Validate ranges (day 1-31, month 1-12) in addition to type."],"tags":["type-validation","date","calendar","zellers-congruence"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}