- Related Questions & Answers
- C Program for N-th term of Arithmetic Progression series
- C Program for N-th term of Geometric Progression series
- Find nth term of a given recurrence relation in C++
- Find nth term of a given recurrence relation in Python
- Find the missing number in Arithmetic Progression in C++
- Find nth term of the Dragon Curve Sequence in C++
- 8086 program to generate AP series of n numbers
- Find the Nth term of the series where each term f[i] = f[i – 1] – f[i – 2] in C++
- Sum of series with alternate signed squares of AP
- Missing Number In Arithmetic Progression using C++
- Program to find Nth term divisible by a or b in C++
- How to create geometric progression series in R?
- JavaScript code for recursive Fibonacci series
- C++ Program for sum of arithmetic series
- Find duplicate element in a progression of first n terms JavaScript

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

We are required to write a JavaScript function that takes in three numbers as argument (first two numbers are supposed to be the starting two consecutive terms of an arithmetic progression).

And the third number, say n, is the 1 index-based element of the series whose value we are required to calculate

For example −

If the input is 2, 5, 7

Then the series will be −

2, 5, 8, 11, 14, 17, 20

And the output should be 20.

Following is the code −

const a = 2, b = 5; const N = 7; const findNthTerm = (first, second, num) => { const diff = second - first; const fact = (num - 1) * diff; const term = first + fact; return term; }; console.log(findNthTerm(a, b, N));

Following is the output in the console −

20

Advertisements