- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Finding length, width and height of the sheet required to cover some area using JavaScript
Problem
We are required to write a JavaScript function that takes in the length, height and width of a room.
Our function should calculate the number of sheets required to cover the whole room given that the width of one single sheet is .52 units and length is 10 units.
For the sake of convenience, we should return the number of rolls such that the length is 15% more than the required length.
Example
Following is the code −
const findSheet = (length, width, height) => { if(length === 0 || width === 0){ return 0; } const roomArea = 2 * (length + width) * height; const rollArea = 0.52 * 10; const required = Math.ceil(roomArea / rollArea * 1.15); return required; }; console.log(findSheet(4, 3.5, 3));
Output
10
Advertisements