easy Math

Factorial

Write a function factorial that takes a non-negative integer and returns its factorial.

Function Signature

function factorial(num);

Example 1:

Input: num = 5
Output: 120
Explanation: The factorial of 5 is 5! = 5 * 4 * 3 * 2 * 1 = 120.

Example 2:

Input: num = 0
Output: 1
Explanation: The factorial of 0 is defined as 1.

Example 3:

Input: num = 3
Output: 6
Explanation: The factorial of 3 is 3! = 3 * 2 * 1 = 6.

Solve this problem

Start your 7-day free trial to solve this problem in our code editor with instant feedback.

Start 7-Day Free Trial to Solve This Problem

Related Problems

Two Sum

easy

Write a function `twoSum` that takes two integers `a` and `b` and returns their sum. ## Function Signature ```function twoSum(a, b);``` ### Example 1: > **Input:** `a = 3, b = 5`\ > **Output:** `8`\ > **Explanation:** The sum of `3` and `5` is `8`. ### Example 2: > **Input:** `a = -2, b = -4`\ > **Output:** `-6`\ > **Explanation:** The sum of `-2` and `-4` is `-6`. ### Example 3: > **Input:** `a = 100, b = 200`\ > **Output:** `300`\ > **Explanation:** The sum of `100` and `200` is `300`.

Math

Multiply

easy

Write a function `multiply` that takes two integers `a` and `b` and returns their product. ## Function Signature ```function multiply(a, b);``` ### Example 1: > **Input:** `a = 3, b = 5`\ > **Output:** `15`\ > **Explanation:** The product of `3` and `5` is `15`. ### Example 2: > **Input:** `a = -2, b = -4`\ > **Output:** `8`\ > **Explanation:** The product of `-2` and `-4` is `8`. ### Example 3: > **Input:** `a = 0, b = 200`\ > **Output:** `0`\ > **Explanation:** The product of `0` and `200` is `0`.

Math

Is Even

easy

Write a function `isEven` that takes an integer and returns true if it is even, false otherwise. ## Function Signature ```function isEven(num);``` ### Example 1: > **Input:** `num = 4`\ > **Output:** `true`\ > **Explanation:** The number 4 is even. ### Example 2: > **Input:** `num = 7`\ > **Output:** `false`\ > **Explanation:** The number 7 is not even. ### Example 3: > **Input:** `num = 0`\ > **Output:** `true`\ > **Explanation:** The number 0 is even.

Math