 
  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
Finding the height based on width and screen size ratio (width:height) in JavaScript
Problem
We are required to write a JavaScript function that takes in the width of the screen as the first argument and the aspect ratio (w:h) as the second argument. Based on these two inputs our function should return the height of the screen.
Example
Following is the code −
const ratio = '18:11'; const width = 2417; const findHeight = (ratio = '', width = 1) => {    const [w, h] = ratio    .split(':')    .map(Number);    const height = (width * h) / w;    return Math.round(height); }; console.log(findHeight(ratio, width)); Output
Following is the console output −
1477
Advertisements
 