

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 if number falls in Fibonacci series or not - JavaScript
We are required to write a JavaScript function that takes in a number and checks whether it falls in Fibonacci series or not. We should return a boolean.
Following is the code to check for Fibonacci −
Example
const num = 89; const isFib = query => { if(query === 0 || query === 1){ return true; } let prev = 1; let count = 2; let temp = 0; while(count <= query){ if(prev + count === query){ return true; }; temp = prev; prev = count; count += temp; }; return false; }; console.log(isFib(num));
Output
Following is the output in the console −
true
- Related Questions & Answers
- Check whether a number is a Fibonacci number or not JavaScript
- Validate a number as Fibonacci series number in JavaScript
- Check if given number is Emirp Number or not in Python
- Check if a number is jumbled or not in C++
- PHP program to check if a given number is present in an infinite series or not
- Check if a number is an Unusual Number or not in C++
- Check if a number is a Krishnamurthy Number or not in C++
- Check if a number is an Achilles number or not in C++
- Check if a number is an Achilles number or not in Python
- Check if the given number is Ore number or not in Python
- Check if number is palindrome or not in Octal in Python
- Check if a number is Quartan Prime or not in C++
- Check if a given number is sparse or not in C++
- Check if a number is Primorial Prime or not in C++
- Check if a number is Primorial Prime or not in Python
Advertisements