0
0
Typescriptprogramming~15 mins

Control flow analysis behavior in Typescript - Mini Project: Build & Apply

Choose your learning style9 modes available
Control flow analysis behavior
📖 Scenario: You are building a simple TypeScript program that uses control flow to check user age and determine access permission.
🎯 Goal: Create a program that uses control flow analysis to check if a user is an adult and print the correct message.
📋 What You'll Learn
Create a variable age with a number value.
Create a variable isAdult that will hold a boolean value.
Use an if statement to set isAdult to true if age is 18 or more, otherwise false.
Print the message "User is an adult" if isAdult is true, otherwise print "User is not an adult".
💡 Why This Matters
🌍 Real World
Control flow analysis helps programs make decisions based on data, like checking user permissions or validating input.
💼 Career
Understanding control flow is essential for writing correct and safe TypeScript code in web development and software engineering.
Progress0 / 4 steps
1
Create the age variable
Create a variable called age and set it to the number 20.
Typescript
Need a hint?

Use let age: number = 20; to create the variable.

2
Create the isAdult variable
Create a variable called isAdult and set it to false.
Typescript
Need a hint?

Use let isAdult: boolean = false; to create the variable.

3
Use if statement to update isAdult
Use an if statement with the condition age >= 18 to set isAdult to true inside the block.
Typescript
Need a hint?

Write if (age >= 18) { isAdult = true; } to update the variable.

4
Print the correct message based on isAdult
Use an if statement to print "User is an adult" if isAdult is true, otherwise print "User is not an adult".
Typescript
Need a hint?

Use if (isAdult) { console.log("User is an adult"); } else { console.log("User is not an adult"); }.