Hi dev,
In this article we will learn about check landscape or portrait using javascript. Let's start …
Syntax & Example:
landscape-portrait.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>landscape-portrait</title>
<link rel="stylesheet" type="text/css" href="../style.css" />
</head>
<body>
<h1>3-landscape-portrait!</h1>
<h3>Write a function which checks given width and height, returns true (landscape) if width is greater than height and vice versa</h3>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
Syntax & Example:
script.js
console.log('3-landscape-portrait');
function isLandscape(width, height){
// 3. ternary short syntax
return (width > height);
}
let checkWidthHeight1 = isLandscape(800, 600);
console.log('Landscape:',checkWidthHeight1);
let checkWidthHeight2 = isLandscape(600, 800);
console.log('Landscape:',checkWidthHeight2);
let checkWidthHeight3 = isLandscape(1024, 768);
console.log('Landscape:',checkWidthHeight3);
Hope it can help you…
Categories : JavaScript
Tags : HTML