 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Problem Can we fit remaining passengers in the bus using JavaScript
Problem
We are required to write a JavaScript function that takes in three parameters −
- cap − is the amount of people the bus can hold excluding the driver. 
- on − is the number of people on the bus excluding the driver. 
- wait − is the number of people waiting to get on to the bus excluding the driver. 
If there is enough space, we should return 0, and if there isn't, we should return the number of passengers we can't take.
Example
Following is the code −
const cap = 120; const on = 80; const wait = 65; const findCapacity = (cap, on, wait) => {    let x = 0;    let y = (on + wait);    if(y > cap){       x += (y - cap);    };    if(x < 0){       x = 0;    };    return x; }; console.log(findCapacity(cap, on, wait)); Output
25
Advertisements
 