Skip to content

Instantly share code, notes, and snippets.

@buymed-hoangpham
Last active September 5, 2022 01:58
Show Gist options
  • Save buymed-hoangpham/3ca0352bd6fd5a5b57faec59f4bdfb77 to your computer and use it in GitHub Desktop.
Save buymed-hoangpham/3ca0352bd6fd5a5b57faec59f4bdfb77 to your computer and use it in GitHub Desktop.
Excerise conditional logic
// 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);
@QuocCao-dev
Copy link

image
có thể tham khảo thêm code này nhé.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment