Skip to content

Commit 47dd2ae

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 3142820 + 9292593 commit 47dd2ae

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
3+
Level: Beginner
4+
5+
CODING CHALLENGE 4
6+
7+
8+
9+
10+
Implement a function that can detect whether an image is landscape.
11+
The function should take two parameters: the width and height of an image.
12+
13+
If it the width parameter returns true, then the image is landscape
14+
(which means width is greater than height).
15+
Otherwise - if the height is greater than the width - it returns false.
16+
17+
18+
SOLUTION 👇🏼
19+
20+
*/
21+
22+
23+
24+
25+
26+
27+
28+
// With comments:
29+
30+
31+
function isLandscape(width, height) {
32+
// 1. Create a conditional ternary operator
33+
// explicit: (width > height) ? true : false
34+
// implicit: (width > height)
35+
36+
// 2. Store the value of the expression in a variable
37+
const calculateRatio = (width > height);
38+
39+
// 3. Use an 'if...else' conditional statement to display different messages.
40+
if(calculateRatio) {
41+
return 'Your image is portrait.';
42+
} else {
43+
return 'Your image is landscape.';
44+
}
45+
}
46+
47+
console.log(isLandscape(10,40));
48+
49+
50+
51+
52+
/* ------------------------------------ */
53+
54+
// Without comments:
55+
56+
57+
function isLandscape(width, height) {
58+
const calculateRatio = (width > height);
59+
60+
if(calculateRatio) {
61+
return 'Your image is portrait.';
62+
} else {
63+
return 'Your image is landscape.';
64+
}
65+
}
66+
67+
console.log(isLandscape(10,40));

0 commit comments

Comments
 (0)