0
0
Typescriptprogramming~15 mins

Tuple with fixed length and types in Typescript - Mini Project: Build & Apply

Choose your learning style9 modes available
Tuple with fixed length and types
📖 Scenario: You are creating a simple program to store information about a book using a tuple. Each book has a fixed set of details: title, number of pages, and whether it is a bestseller.
🎯 Goal: Build a TypeScript tuple with fixed length and types to hold book information, then access and display the data.
📋 What You'll Learn
Create a tuple with exactly three elements: a string, a number, and a boolean
Use a variable named book to store the tuple
Create a variable named isBestseller to hold the boolean value from the tuple
Print the book title and bestseller status using console.log
💡 Why This Matters
🌍 Real World
Tuples are useful when you want to group a fixed number of related values with different types, like storing a book's details or coordinates.
💼 Career
Understanding tuples helps in writing clear and type-safe code, which is important for software development jobs using TypeScript or similar languages.
Progress0 / 4 steps
1
Create a tuple with fixed length and types
Create a tuple called book with these exact values and types: "The Alchemist" (string), 208 (number), and true (boolean).
Typescript
Need a hint?

Use square brackets to define the tuple type and assign the values in the same order.

2
Extract the bestseller status from the tuple
Create a variable called isBestseller and assign it the third element of the book tuple.
Typescript
Need a hint?

Remember tuple elements are accessed by their index starting at 0.

3
Access and print the book title and bestseller status
Use console.log to print the book title from book[0] and the isBestseller variable in this exact format: "Title: The Alchemist, Bestseller: true".
Typescript
Need a hint?

Use a template string (backticks) to insert variables inside the string.

4
Display the final output
Run the program to display the output showing the book title and bestseller status exactly as: Title: The Alchemist, Bestseller: true.
Typescript
Need a hint?

Make sure your console.log prints exactly as shown.