diff --git a/src/math.ts b/src/math.ts index ea72e07..ca396d4 100644 --- a/src/math.ts +++ b/src/math.ts @@ -1,18 +1,30 @@ // ### LEVEL 1: The Basics ### export function add(x: number, y: number): number { // TODO: Return the sum of x and y - throw new Error("Not implemented"); + return x + y; } // ### LEVEL 2: Fizz Buzz ### export function fizzBuzz(value: number): string { // TODO: Return Fizz if value is divisible by 3, Buzz if value is divisible by 5, // FizzBuzz if value is divisible by 3 and 5, and the value as a string otherwise - throw new Error("Not implemented"); + if (value % 3 === 0) { + if (value % 5 === 0) { + return "FizzBuzz"; + } + + return "Fizz"; + } + + if (value % 5 === 0) { + return "Buzz"; + } + + return value.toString(); } // ### LEVEL 3: Length of vector ### export function getLengthOfVector(vec: [number, number]): number { // TODO: Return the length of the vector - throw new Error("Not implemented"); + return Math.sqrt(vec[0] * vec[0] + vec[1] * vec[1]); }