0
0
Typescriptprogramming~15 mins

Boolean type behavior in Typescript - Mini Project: Build & Apply

Choose your learning style9 modes available
Boolean type behavior
📖 Scenario: Imagine you are creating a simple system to check if a user is allowed to access a website feature based on their subscription status.
🎯 Goal: You will create a boolean variable to represent the subscription status, then use it to decide if the user can access the feature.
📋 What You'll Learn
Create a boolean variable named isSubscribed with the value true.
Create a boolean variable named hasTrial with the value false.
Create a boolean variable named canAccessFeature that is true if isSubscribed or hasTrial is true.
Print the value of canAccessFeature.
💡 Why This Matters
🌍 Real World
Boolean variables are used everywhere to represent yes/no, true/false, or on/off states in programs.
💼 Career
Understanding boolean logic is essential for controlling program flow and making decisions in software development.
Progress0 / 4 steps
1
Create subscription status variables
Create a boolean variable called isSubscribed and set it to true. Also create a boolean variable called hasTrial and set it to false.
Typescript
Need a hint?

Use let to declare variables and assign true or false directly.

2
Create access control variable
Create a boolean variable called canAccessFeature that is true if either isSubscribed or hasTrial is true. Use the logical OR operator ||.
Typescript
Need a hint?

Use || to combine two boolean variables.

3
Check access with if statement
Write an if statement that checks if canAccessFeature is true. Inside the if, create a variable message with the value 'Access granted'. Otherwise, set message to 'Access denied'.
Typescript
Need a hint?

Use if (canAccessFeature) to check the boolean and assign message accordingly.

4
Print the access message
Write a console.log statement to print the value of the variable message.
Typescript
Need a hint?

Use console.log(message); to show the message in the console.