Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ is how you see the results of your code.

🐨 Open <InlineFile file="index.ts" /> and complete the following tasks:

1. Use `console.log()` to print the string `"Hello, World!"`
2. Use `console.log()` to print your name as a string
1. Use `console.log()` to print the exact string `"Hello, World!"` (capital H,
capital W, comma, and exclamation mark)
2. Use `console.log()` to print your name as a string on a second line

## Completion criteria

When you run the program, the output should include:

- A line containing `Hello, World!`
- At least one more non-empty line (your name)

💰 Strings are text values wrapped in quotes (single or double).

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Your First Program
// Let's print some messages to the console!

// 🐨 Use console.log() to print "Hello, World!"
// 🐨 Use console.log() to print the exact string "Hello, World!"

// 🐨 Use console.log() to print your name (as a string)
// 🐨 Use console.log() to print your name (as a string) on a second line
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,23 @@ console.log('Name:\tKody') // Prints with a tab between

🐨 Open <InlineFile file="index.ts" /> and complete the following tasks:

1. Log a string using single quotes that contains an apostrophe (like "It's
working!")
2. Log a string using double quotes that contains a quoted phrase (like: She
said "Hi")
3. Log "Hello" and "World" on separate lines using `\n` in a single string
4. Log tab-separated column headers: "Name:" "Age:" "City:" using `\t`
1. Log the exact string `It's working!` using a single-quoted string (escape the
apostrophe)
2. Log the exact string `She said "Hi"` using a double-quoted string (escape the
inner quotes)
3. In a single string, log `Hello` and `World` on separate lines (use a newline
escape)
4. Log the exact tab-separated headers: `Name:` then tab then `Age:` then tab
then `City:`

## Completion criteria

Your program output should include all four of these (exact text and whitespace):

- `It's working!`
- `She said "Hi"`
- `Hello` and `World` separated by a newline in one log
- `Name:\tAge:\tCity:` (tabs between the labels)

💰 Use backslash escape sequences for quotes, newlines, and tabs. The table
above is your reference.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Escaping Strings
// Learn to include special characters in strings

// 🐨 Log "It's working!" using single quotes (you'll need to escape the apostrophe)
// 🐨 Log exactly: It's working! (single-quoted string; escape the apostrophe)

// 🐨 Log: She said "Hi" (using double quotes for the string)
// 🐨 Log exactly: She said "Hi" (double-quoted string; escape the inner quotes)

// 🐨 Log "Hello" and "World" on separate lines using a single string with \n
// 🐨 Log "Hello" and "World" on separate lines using a single string with a newline escape

// 🐨 Log tab-separated data: Name: [tab] Age: [tab] City: (like column headers)
// 🐨 Log exactly: Name: [tab] Age: [tab] City:
16 changes: 12 additions & 4 deletions exercises/01.expressions-and-output/03.problem.strings/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ console.log('Hello' + ' ' + 'World') // Prints: Hello World

🐨 Open <InlineFile file="index.ts" /> and complete the following tasks:

1. Log the result of concatenating `"Hello"` and `"TypeScript"` with a space
between them
2. Log your first name and last name concatenated together
3. Log a longer message by concatenating multiple strings
1. Concatenate the strings `"Hello"`, a space, and `"TypeScript"`, then log the
result (output must include `Hello TypeScript`)
2. Concatenate your first name, a space, and your last name, then log the result
3. Concatenate multiple small string pieces to produce exactly:
`I am learning to code` (include the spaces between words)

## Completion criteria

- Output includes `Hello TypeScript`
- Output includes `I am learning to code`
- Your source uses the `+` operator to concatenate string literals at least
three times (this step is about concatenation, not template literals)

💰 Remember to include spaces where you need them - the `+` operator joins
strings exactly as they are!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// String Expressions
// Learn to work with text data

// 🐨 Log "Hello" + " " + "TypeScript" (concatenate these three strings)
// 🐨 Log the concatenation of "Hello", a space, and "TypeScript"

// 🐨 Log your first name and last name concatenated together with a space

// 🐨 Log a sentence by concatenating multiple strings
// 🐨 Log the sentence "I am learning to code" by concatenating multiple strings
// 💰 Build the sentence from small pieces and include spaces where needed
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const output = getOutput()
await test('should print Hello TypeScript', () => {
assert.ok(
output.includes('Hello TypeScript'),
'🚨 Output should include "Hello TypeScript" - concatenate "Hello" + " " + "TypeScript"',
'🚨 Output should include "Hello TypeScript" - concatenate those three pieces with +',
)
})

Expand Down
18 changes: 14 additions & 4 deletions exercises/01.expressions-and-output/04.problem.numbers/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ a complete list in the

🐨 Open <InlineFile file="index.ts" /> and complete the following tasks:

1. Log the result of adding 25 and 17
2. Log the result of multiplying 8 by 6
3. Log the result of dividing 100 by 4
4. Log the result of a more complex expression: `(10 + 5) * 2`
1. Log the result of adding `25` and `17`
2. Log the result of multiplying `8` by `6`
3. Log the result of dividing `100` by `4`
4. Log the result of adding `10` and `5`, then multiplying that sum by `2`
(group the addition so it happens first)

## Completion criteria

Your output should include these numeric results (each on its own line is fine):

- `42` (from 25 + 17)
- `48` (from 8 × 6)
- `25` (from 100 ÷ 4)
- `30` (from (10 + 5) × 2)

💰 You can use parentheses to control the order of operations, just like in
regular math!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

// 🐨 Use console.log to show the result of 100 divided by 4

// 🐨 Use console.log to show the result of (10 + 5) multiplied by 2
// 💰 Use parentheses to control order of operations
// 🐨 Use console.log to show the result of adding 10 and 5, then multiplying by 2
// 💰 Use parentheses so the addition happens before the multiplication
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,22 @@ console.log(`Hello, ${'World'}!`) // Prints: Hello, World!

🐨 Open <InlineFile file="index.ts" /> and complete the following tasks:

1. Log a template literal that says "The answer is 42" using `${40 + 2}`
2. Log a greeting that includes "Hello" and "TypeScript" in one template literal
3. Log a math problem and its answer, like "10 times 5 equals 50"
1. Log a template literal whose output is exactly `The answer is 42`, embedding a
calculation that evaluates to `42` (do not hardcode the digits `42` as plain
text alone)
2. Log a greeting template literal that includes both `Hello` and `TypeScript`
(for example: `Hello, TypeScript!`)
3. Log a math sentence whose output includes `50` as the computed answer (for
example: `10 times 5 equals 50`), embedding the multiplication in the
template

## Completion criteria

Your output should include:

- `The answer is 42`
- Text containing both `Hello` and `TypeScript` (any casing is fine for the check)
- The number `50` as part of a logged math sentence

💰 The backtick key is usually in the top-left of your keyboard, below Escape.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Template Literals
// A better way to build strings

// 🐨 Log "The answer is 42" using a template literal with ${40 + 2}
// 🐨 Log "The answer is 42" using a template literal
// 💰 Embed a calculation that evaluates to 42

// 🐨 Log "Hello, TypeScript!" using a template literal
// 🐨 Log a greeting that includes "Hello" and "TypeScript" using a template literal

// 🐨 Log a math problem like "10 times 5 equals 50"
// 🐨 Log a math sentence whose answer is 50 (embed the multiplication)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const output = getOutput()
await test('should print "The answer is 42"', () => {
assert.ok(
output.includes('The answer is 42'),
'🚨 Output should include "The answer is 42" - use a template literal with ${40 + 2}',
'🚨 Output should include "The answer is 42" - use a template literal and embed a calculation for 42',
)
})

Expand All @@ -41,6 +41,6 @@ await test('should print Hello, TypeScript! greeting', () => {
await test('should print math result with 50', () => {
assert.ok(
output.includes('50'),
'🚨 Output should include 50 (the result of 10 * 5) - use ${10 * 5} in a template literal',
'🚨 Output should include 50 as the computed answer in a template-literal math sentence',
)
})
30 changes: 25 additions & 5 deletions exercises/02.variables/01.problem.let-and-const/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,31 @@ product prices).

🐨 Open <InlineFile file="index.ts" /> and:

1. Create a `const` for `TAX_RATE` set to `0.08`
2. Create a `let` for `cartTotal` starting at `0`
3. Create `const` variables for product prices: `bookPrice`, `muffinPrice`, and `laptopPrice`
4. Add items to the cart by updating `cartTotal`
5. Try to reassign `TAX_RATE` and see what TypeScript says
1. Create a `const` named `TAX_RATE` set to `0.08`
2. Create a `let` named `cartTotal` starting at `0`
3. Create `const` product prices with these exact values:
- `bookPrice` = `15.99`
- `muffinPrice` = `4.5`
- `laptopPrice` = `999.99`
4. Add the book and the muffin to the cart by updating `cartTotal` (do **not**
add the laptop for this step)
5. Create `finalTotal` as the cart subtotal plus 8% tax (`TAX_RATE`)
6. Try to reassign `TAX_RATE` (keep it commented after you see the TypeScript
error) and export your results

## Required exports

Export these names so the tests can verify your work:

- `TAX_RATE`
- `cartTotal`
- `finalTotal`

## Completion criteria (with the fixtures above)

- `TAX_RATE` is `0.08`
- `cartTotal` is `20.49` (book + muffin only)
- `finalTotal` is `22.1292` (subtotal + 8% tax)

💰 By convention, constants that represent fixed values are often UPPER_CASE:

Expand Down
16 changes: 8 additions & 8 deletions exercises/02.variables/01.problem.let-and-const/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
// 🐨 Create a variable `cartTotal` using `let`, starting at 0

// 🐨 Create constants for product prices:
// - bookPrice is $15.99
// - muffinPrice is $4.5
// - laptopPrice is $999.99
// 💰 note, TypeScript doesn't know/care about whether the number represents
// money, a count, or anything, so you don't use the dollar sign in this syntax
// - bookPrice is 15.99
// - muffinPrice is 4.5
// - laptopPrice is 999.99
// 💰 TypeScript doesn't know/care whether the number represents money or a
// count, so you don't use a dollar sign in the syntax

// 🐨 Add the book to the cart (update cartTotal)

// 🐨 Add the muffin to the cart (update cartTotal)
// 💰 Leave the laptop out of the cart for this exercise

// 🐨 Calculate the final total with tax
// 💰 Include tax when computing the final total
// 🐨 Create `finalTotal` as cartTotal plus 8% tax using TAX_RATE

// 🐨 Try uncommenting the line below - what happens?
// TAX_RATE = 0.10
Expand All @@ -27,5 +27,5 @@
// console.log('Tax:', cartTotal * TAX_RATE)
// console.log('Final total:', finalTotal)

// 🐨 Export your variables so we can verify your work
// 🐨 Export TAX_RATE, cartTotal, and finalTotal so we can verify your work
// export { TAX_RATE, cartTotal, finalTotal }
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ await test('cartTotal should be calculated correctly', () => {
// cartTotal = bookPrice + muffinPrice = 15.99 + 4.5 = 20.49
assert.ok(
Math.abs(solution.cartTotal - 20.49) < Math.pow(10, -2),
'🚨 cartTotal should be 20.49 - add bookPrice and muffinPrice together',
'🚨 cartTotal should be 20.49 - add the book and muffin prices (not the laptop)',
)
})

Expand All @@ -43,6 +43,6 @@ await test('finalTotal should include tax', () => {
// finalTotal = cartTotal + cartTotal * TAX_RATE = 20.49 + 20.49 * 0.08 = 22.1292
assert.ok(
Math.abs(solution.finalTotal - 22.1292) < Math.pow(10, -4),
'🚨 finalTotal should be 22.1292 - add the tax (cartTotal * TAX_RATE) to cartTotal',
'🚨 finalTotal should be 22.1292 - subtotal plus 8% tax',
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,31 @@ obj.count = 2 // The object itself is modified (mutated)
properties on a `const` object.
</callout-warning>

🐨 Open <InlineFile file="index.ts" /> and:
🐨 Open <InlineFile file="index.ts" />. The starter already declares:

1. Try to reassign the `const` object (see the error)
2. Mutate the `const` object by changing `age` to `31` and `city` to
`'Portland'`
3. Observe that mutation works even with `const`
```ts
const person = { name: 'Alice', age: 30, city: 'Seattle' }
```

Complete these tasks:

1. Try to reassign `person` to a new object (uncomment the line and observe the
TypeScript error), then leave that reassignment commented out
2. Mutate `person` so `age` becomes `31` and `city` becomes `'Portland'`
(`name` stays `'Alice'`)
3. Export `person`

## Required exports

- `person`

## Completion criteria

After mutation, `person` must deep-equal:

```ts
{ name: 'Alice', age: 31, city: 'Portland' }
```

💰 Mutation means changing properties on the existing object (not replacing the
object itself).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ console.log('Modified person:', person)
// The variable person always points to the SAME object,
// but the properties of that object can change.

// 🐨 Export your variable so we can verify your work
// 🐨 Export person so we can verify your work
// export { person }
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@ We need to track:

🐨 Open <InlineFile file="index.ts" /> and complete the following tasks:

1. Create a variable `price` with type `number` set to `29.99`
2. Create a variable `productName` with type `string` set to `"TypeScript Guide"`
3. Create a variable `quantity` with type `number` set to `100`
4. Create a `description` variable that uses a template literal to combine the
product info
1. Create `price` with type `number` set to `29.99`
2. Create `productName` with type `string` set to `"TypeScript Guide"`
3. Create `quantity` with type `number` set to `100`
4. Create `description` as a string (prefer a template literal) with this exact
value:
`Product: TypeScript Guide | Price: $29.99 | In Stock: 100`

## Required exports

Export: `price`, `productName`, `quantity`, `description`

## Completion criteria

- `price` is the number `29.99`
- `productName` is `"TypeScript Guide"`
- `quantity` is the number `100`
- `description` matches the exact formatted string above (including `$`, spaces,
and `|` separators)

💰 Template literals let you embed expressions inside a string.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// 🐨 Create a variable `quantity` with type `number` set to 100

// 🐨 Create a `description` using a template literal that outputs:
// 🐨 Create a `description` using a template literal that equals exactly:
// "Product: TypeScript Guide | Price: $29.99 | In Stock: 100"

// ✅ These console.logs will verify your work
Expand All @@ -16,5 +16,5 @@
// console.log('Quantity:', quantity)
// console.log('Description:', description)

// 🐨 Export your variables so we can verify your work
// 🐨 Export price, productName, quantity, and description
// export { price, productName, quantity, description }
Loading
Loading