- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check whether a number is a Fibonacci number or not JavaScript
We are required to write a JavaScript function that takes in a number and returns a boolean based on the fact whether or not it comes in the fibonacci series.
For example −
If the function call is like this −
fibonacci(12); fibonacci(89); fibonacci(55); fibonacci(534);
Then the output should be −
False true true false
Now, let’s write a recursive solution to this problem −
Example
const fibonacci = (query, count = 1, last = 0) => { if(count < query){ return fibonacci(query, count+last, count); }; if(count === query){ return true; } return false; }; console.log(fibonacci(12)); console.log(fibonacci(55)); console.log(fibonacci(89)); console.log(fibonacci(534));
Output
The output in the console will be −
false true true false
- Related Articles
- Check if number falls in Fibonacci series or not - JavaScript
- How to check whether a number is a prime number or not?
- How to check whether a number is finite or not in JavaScript?
- How To Check Whether a Number Is a Pronic Number or Not in Java?
- How To Check Whether a Number Is a Bouncy Number or Not in Java?
- How To Check Whether a Number is a Evil Number or Not in Java?
- How To Check Whether a Number Is a Fascinating Number or Not in Java?
- How To Check Whether a Number is a Harshad Number or Not in Java?
- How To Check Whether a Number Is a Insolite Number or Not in Java?
- How To Check Whether a Number is a Keith Number or Not in Java?
- How To Check Whether a Number Is a Niven Number or Not in Java?
- How To Check Whether a Number is a Sunny Number or Not in Java?
- How to Check Whether a Number is a Triangular Number or Not in Java?
- How To Check Whether a Number is a Unique Number or Not in Java?
- How To Check Whether a Number is a Goldbach Number or Not in Java?

Advertisements