Returning the nth even number using JavaScript


Problem

We are required to write a JavaScript function that takes in a number n. And our function should simply return the nth even number in natural numbers.

Example

Following is the code −

 Live Demo

const num = 67765;
const nthEven = (num = 1) => {
   const next = num * 2;
   const res = next - 2;
   return res;
};
console.log(nthEven(num));

Output

135528

Updated on: 17-Apr-2021

453 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements