MCPcopy
hub / github.com/mouredev/hello-javascript / sumIntegers

Function sumIntegers

Basic/24-error-handling.js:56–67  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

54// throw new Error("Se ha producido un error")
55
56function sumIntegers(a, b) {
57 if (typeof a !== "number" || typeof b !== "number") {
58 throw new TypeError("Esta operación sólo suma números")
59 }
60 if (!Number.isInteger(a) || !Number.isInteger(b)) {
61 throw new Error("Esta operación sólo suma números enteros")
62 }
63 if (a == 0 || b == 0) {
64 throw new SumZeroIntegerError("Se está intentando sumar cero", a, b)
65 }
66 return a + b
67}
68
69try {
70 console.log(sumIntegers(5, 10))

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected