Skip to content

Practical Challenges of Logical Operators in JavaScript

MorettiOS/logical-operator-challenges

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 Logical Operators in JavaScript – My Learning Journey 📝 About This Guide I'm learning about logical operators, so I'll document all my challenges and experiments here.

🎯 Challenge 1: The Trusted Messenger Goal: You're building a notification system. // If the user has a preferred email, use it; // otherwise use the secondary email. // If neither exists, send to the emergency email.

🎯 Challenge 2: Secret Portal Goal: The portal opens if and only if the player satisfies at least one criterion.

🎯 Challenge 3: TheSurprisebonus Goal: Determines free shipping eligibility based on: // VIP status (case-insensitive "yes") // Order total (>= $200) // Active promotion flag

🎯 Challenge 4: The Mysterious Name // A system collects user names, but some fields may be empty ("", null, undefined). // If the name is invalid, you should use: // The user's nickname (if it exists) // Otherwise, "Guest" + random number // How to do this with ||?

🎯 Challenge 5: The Voice Assistant // A virtual assistant responds with: // The custom response from the database, OR // The default system response, OR // Silence (if nothing is found).

(Future challenges can follow the same format!)

🧠 Logical Operators in JavaScript – My Learning Journey 📝 About This Guide I'm documenting my experiments with logical operators (|| and &&) through practical challenges.

📝 OR (||) Challenges 🎯 Challenge 1: The Trusted Messenger Goal: Build a notification system that: // Uses the user’s preferred email if available, // Falls back to their secondary email, // Defaults to an emergency email if neither exists.

🎯 Challenge 2: Secret Portal Goal: The portal unlocks if the player meets at least one of the criteria.

🎯 Challenge 3: The Surprise Bonus Goal: Grant free shipping if: // User is a VIP ("yes", case-insensitive), // Order total ≥ $200, // An active promotion is running.

🎯 Challenge 4: The Mysterious Name Goal: Handle invalid names ("", null, undefined) by using: // The user’s nickname (if valid), // Otherwise, assign "Guest" + random number. (How to solve this with ||?)

🎯 Challenge 5: The Voice Assistant Goal: Respond with: // A custom response from the database, // Or the default system response, // Or silence if no data exists.

📝 AND (&&) Challenges 🎯 Challenge 1: E-commerce Checkout Validation Goal: Ensure: // Shipping address is complete, // Payment method is selected, // Cart is not empty.

Where && comes in: // The "Complete Purchase" button enables only if all conditions are true.

🎯 Challenge 2: Bank App Login Goal: Allow access only if: // CPF and password are correct, // User is not blocked, // Device is authorized.

Where && comes in: // The "Access Account" button requires all conditions.

🎯 Challenge 3: Social Media Post Goal: Publish only if: // Text is valid (not empty/within limits), // No recent policy violations, // Media (if attached) has a valid format.

Where && comes in: // The "Publish" button checks all rules.

🎯 Challenge 4: Premium Video Access Control Goal: Unlock video only for users who: // Have an active subscription, // Are not on a free trial, // Are in a supported country.

Where && comes in: // Content loads only if all conditions pass.

🎯 Challenge 5: Multiplayer Mode Goal: Grant access only if: // Tutorial is completed, // Internet is stable, // Player is not banned.

Where && comes in: // Ensures a fair and secure multiplayer experience.

📝 Nullish Coalescing Operator (??) Challenges

🎯 Challenge 1: Default Name Your variable name might be undefined or null. If it is, display "Anonymous" in the console. (Hint: Use ?? to assign the default value)

🎯 Challenge 2: Coin Counter You have a variable coins that could be null or undefined. If it is, assume the person has 0 coins. How would you use ?? to solve this?

🎯 Challenge 3: Favorite Color The variable favoriteColor might be undefined (not set). If it is, assign "blue" as the default color.

🎯 Challenge 4: Check Age A variable age could be null (e.g., if the user didn’t provide it). Replace null with "Not provided" using ??.

🎯 Challenge 5: Sound Preference The variable volume might be undefined (not configured). If it is, set defaultVolume to 50. How would you do this with ???

(Future challenges will follow this format!)

About

Practical Challenges of Logical Operators in JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published