0
0
Javascriptprogramming~15 mins

Logical operators in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Logical Operators Practice
📖 Scenario: You are building a simple access control system for a small event. You want to check if a person is allowed entry based on their age and whether they have a ticket.
🎯 Goal: Create a program that uses logical operators to decide if a person can enter the event. The program will check if the person is at least 18 years old and if they have a ticket.
📋 What You'll Learn
Create a variable age with the value 20
Create a variable hasTicket with the value true
Create a variable canEnter that uses the logical AND operator to check if age is at least 18 and hasTicket is true
Print the value of canEnter
💡 Why This Matters
🌍 Real World
Logical operators are used in many real-world programs to make decisions based on multiple conditions, like checking user permissions or filtering data.
💼 Career
Understanding logical operators is essential for programming jobs because they help control the flow of programs and implement rules.
Progress0 / 4 steps
1
Create initial variables
Create a variable called age and set it to 20. Create another variable called hasTicket and set it to true.
Javascript
Need a hint?

Use let to create variables. Set age to 20 and hasTicket to true.

2
Create access condition
Create a variable called canEnter that uses the logical AND operator && to check if age is greater than or equal to 18 and hasTicket is true.
Javascript
Need a hint?

Use let canEnter = (age >= 18) && hasTicket; to combine the conditions.

3
Add a condition for underage without ticket
Modify the canEnter variable to also allow entry if the person is under 18 but has a special pass. First, create a variable called hasSpecialPass and set it to false. Then update canEnter to be true if the person is at least 18 and has a ticket, OR if they have a special pass.
Javascript
Need a hint?

Use the logical OR operator || to add the special pass condition.

4
Display the result
Print the value of canEnter using console.log().
Javascript
Need a hint?

Use console.log(canEnter); to show the result.