Skip to content

Commit e6d73c7

Browse files
committed
Add moduleDetection: force to tsconfig, remove unnecessary export {} statements, and fix problem file variables
1 parent 7f06aa9 commit e6d73c7

File tree

7 files changed

+47
-15
lines changed

7 files changed

+47
-15
lines changed

exercises/03.primitive-types/01.problem.numbers-and-strings/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22
// Let's create variables to store product information
33

44
// 🐨 Create a variable `price` with type `number` set to 29.99
5+
const price: number = 29.99
56

67
// 🐨 Create a variable `productName` with type `string` set to "TypeScript Guide"
8+
const productName: string = 'TypeScript Guide'
79

810
// 🐨 Create a variable `quantity` with type `number` set to 100
11+
const quantity: number = 100
912

1013
// 🐨 Create a `description` using a template literal that outputs:
1114
// "Product: TypeScript Guide | Price: $29.99 | In Stock: 100"
1215
// 💰 Use backticks ` and ${variable} syntax
16+
const description = `Product: ${productName} | Price: $${price} | In Stock: ${quantity}`
1317

1418
// ✅ These console.logs will verify your work
1519
console.log('Price:', price)
16-
// @ts-expect-error - 💣 remove this comment once you create the productName variable
1720
console.log('Product:', productName)
18-
// @ts-expect-error - 💣 remove this comment once you create the quantity variable
1921
console.log('Quantity:', quantity)
20-
// @ts-expect-error - 💣 remove this comment once you create the description variable
2122
console.log('Description:', description)
22-
23-
// 🦺 This line ensures TypeScript treats this as a module
24-
export {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Shopping Cart Calculator
2+
// Using loops to process arrays
3+
4+
const prices: Array<number> = [29.99, 9.99, 49.99, 4.99, 19.99]
5+
6+
// 🐨 Create a variable `total` starting at 0
7+
// 💰 let total = 0
8+
9+
// 🐨 Create a variable `expensiveItemCount` starting at 0
10+
// (items over $10)
11+
12+
// 🐨 Write a for loop to iterate through prices
13+
// 💰 for (let i = 0; i < prices.length; i++)
14+
15+
// Inside the loop:
16+
// 🐨 Add the current price to total
17+
// 🐨 If the price is over 10, increment expensiveItemCount
18+
19+
// console.log(`Total: $${total.toFixed(2)}`)
20+
// console.log(`Expensive items (>$10): ${expensiveItemCount}`)

exercises/04.control-flow/02.problem.switch-statements/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,3 @@ const grade: string = 'B'
1616
// 💰 Don't forget the `break` after each case!
1717

1818
// console.log(`Grade ${grade}: ${description}`)
19-
20-
// 🦺 This line ensures TypeScript treats this as a module
21-
export {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Shopping Cart Analysis
2+
// Using for...of for cleaner iteration
3+
4+
const prices: Array<number> = [29.99, 9.99, 49.99, 4.99, 19.99]
5+
6+
// 🐨 Create variables for total, count, and highest price
7+
// let total = 0
8+
// let highestPrice = prices[0]
9+
10+
// 🐨 Use for...of to iterate through prices
11+
// 💰 for (const price of prices)
12+
13+
// Inside the loop:
14+
// 🐨 Add price to total
15+
// 🐨 Check if price is higher than highestPrice, update if so
16+
17+
// 🐨 Calculate the average after the loop
18+
// 💰 const average = total / prices.length
19+
20+
// console.log(`Total: $${total.toFixed(2)}`)
21+
// console.log(`Average: $${average.toFixed(2)}`)
22+
// console.log(`Highest: $${highestPrice.toFixed(2)}`)

exercises/04.control-flow/03.problem.loops/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,3 @@ const prices: Array<number> = [29.99, 9.99, 49.99, 4.99, 19.99]
1818

1919
// console.log(`Total: $${total.toFixed(2)}`)
2020
// console.log(`Expensive items (>$10): ${expensiveItemCount}`)
21-
22-
// 🦺 This line ensures TypeScript treats this as a module
23-
export {}

exercises/04.control-flow/04.problem.for-of-iteration/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,3 @@ const prices: Array<number> = [29.99, 9.99, 49.99, 4.99, 19.99]
2020
// console.log(`Total: $${total.toFixed(2)}`)
2121
// console.log(`Average: $${average.toFixed(2)}`)
2222
// console.log(`Highest: $${highestPrice.toFixed(2)}`)
23-
24-
// 🦺 This line ensures TypeScript treats this as a module
25-
export {}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
3+
"moduleDetection": "force",
34
"target": "ES2022",
45
"module": "ESNext",
56
"moduleResolution": "bundler",

0 commit comments

Comments
 (0)