Skip to content

Commit 6044d08

Browse files
committed
feat: enhance product availability logic and tests
- Introduced a `price` variable to determine discounts and updated the `hasDiscount` logic to check if the price is under 50. - Updated the README to reflect the new task order and removed the `isOnSale` variable from the exercise. - Adjusted test cases to verify the export of `hasDiscount` and its boolean type. - Enhanced console logs for better clarity on product status.
1 parent b0310bd commit 6044d08

4 files changed

Lines changed: 29 additions & 9 deletions

File tree

exercises/03.primitive-types/03.problem.booleans-and-comparisons/README.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ const result3 = (a || b) && c // || happens first, then &&
2626
🐨 Open <InlineFile file="index.ts" /> and complete the following tasks:
2727

2828
1. Create a variable `isAvailable` with type `boolean` set to `true`
29-
2. Create a variable `isOnSale` with type `boolean` set to `false`
30-
3. Create a variable `hasDiscount` that's `true` when the price is under 50
31-
4. Create a variable `canPurchase` that's `true` when the item is available AND
29+
2. Create a variable `hasDiscount` that's `true` when the price is under 50
30+
3. Create a variable `canPurchase` that's `true` when the item is available AND
3231
in stock
33-
5. Create a variable `isNotAvailable` that's the opposite of `isAvailable` using
32+
4. Create a variable `isNotAvailable` that's the opposite of `isAvailable` using
3433
the `!` operator
3534

3635
📜 [MDN - Logical operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#logical_operators)

exercises/03.primitive-types/03.problem.booleans-and-comparisons/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Product Availability System
22
// Using booleans to track product status
33

4+
const price: number = 29.99
45
const stockCount: number = 100
56

67
// 🐨 Create a variable `isAvailable` with type `boolean` set to `true`
@@ -25,4 +26,4 @@ console.log('Can Purchase:', canPurchase)
2526
console.log('Is Not Available:', isNotAvailable)
2627

2728
// 🐨 Export your variables so we can verify your work
28-
// export { isAvailable, isOnSale, hasDiscount, canPurchase, isNotAvailable }
29+
// export { isAvailable, hasDiscount, canPurchase, isNotAvailable }

exercises/03.primitive-types/03.solution.booleans-and-comparisons/index.test.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,26 @@ await test('isAvailable should be true', () => {
2222
)
2323
})
2424

25-
await test('isOnSale is exported', () => {
25+
await test('hasDiscount is exported', () => {
2626
assert.ok(
27-
'isOnSale' in solution,
28-
'🚨 Make sure you export "isOnSale" - add: export { isAvailable, isOnSale, ... }',
27+
'hasDiscount' in solution,
28+
'🚨 Make sure you export "hasDiscount" - add: export { isAvailable, hasDiscount, ... }',
29+
)
30+
})
31+
32+
await test('hasDiscount should be true (price < 50)', () => {
33+
assert.strictEqual(
34+
solution.hasDiscount,
35+
true,
36+
'🚨 hasDiscount should be true when price < 50 - use a comparison: price < 50',
37+
)
38+
})
39+
40+
await test('hasDiscount should be a boolean type', () => {
41+
assert.strictEqual(
42+
typeof solution.hasDiscount,
43+
'boolean',
44+
'🚨 hasDiscount should be a boolean type - use a comparison: price < 50',
2945
)
3046
})
3147

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
// Product Availability System
22
// Using booleans to track product status
33

4+
const price: number = 29.99
45
const stockCount: number = 100
56

67
const isAvailable: boolean = true
78

9+
const hasDiscount: boolean = price < 50
10+
811
const canPurchase: boolean = isAvailable && stockCount > 0
912

1013
const isNotAvailable: boolean = !isAvailable
1114

1215
// ✅ Verification
1316
console.log('Is Available:', isAvailable)
17+
console.log('Has Discount:', hasDiscount)
1418
console.log('Can Purchase:', canPurchase)
1519
console.log('Is Not Available:', isNotAvailable)
1620

17-
export { isAvailable, canPurchase, isNotAvailable }
21+
export { isAvailable, hasDiscount, canPurchase, isNotAvailable }

0 commit comments

Comments
 (0)