Last active
September 5, 2022 01:58
-
-
Save buymed-hoangpham/3ca0352bd6fd5a5b57faec59f4bdfb77 to your computer and use it in GitHub Desktop.
Excerise conditional logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 1. Parity of Number | |
| let n = 2; | |
| const result1 = n % 2 === 0 ? 'even' : 'odd'; | |
| console.log('result1', result1); | |
| // 2. Allow to Contest | |
| const minAge = 7; | |
| const maxAge = 12; | |
| const age = 7; | |
| const result2 = age >= minAge && age <= maxAge ? true : false; | |
| console.log('result2', result2); | |
| // 3.Minimum Value of Three | |
| const a = 7; | |
| const b = 4; | |
| const c = 9; | |
| let min = a; | |
| if (min > b) min = b; | |
| if (min > c) min = c; | |
| console.log('min', min); | |
| // 4. Second Largest Number | |
| const A = 2; | |
| const B = 3; | |
| const C = 1; | |
| let secondLargestNumber; | |
| if (A >= B && A >= C) { | |
| secondLargestNumber = B >= C ? B : C; | |
| } else if (B >= A && B >= C) { | |
| secondLargestNumber = A >= C ? A : C; | |
| } else if (C >= A && C >= B) { | |
| secondLargestNumber = A >= B ? A : B; | |
| } | |
| console.log('secondLargestNumber', secondLargestNumber); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Em đã update lại bài 4. Mong thầy kiểm tra lại giùm e. E cám ơn.