Conditionals allow you to execute different code based on conditions.
Basic syntax:
if (condition) {
// code to execute if condition is true
} else {
// code to execute if condition is false
}
Example:
if (age > 16) {
console.log("You can drive!");
} else {
console.log("Sorry. Too young!");
}
Comparison Operators:
<
: less than>
: greater than<=
: less than or equal to>=
: greater than or equal to===
: equal to!==
: NOT equal to
Remember: Conditions should evaluate to either truthy or falsy.
These allow you to check multiple conditions.
Logical Operators:
!
: NOT||
: OR&&
: AND
Example with the AND operator:
if (sky === "clear" && temp === "warm") {
alert("Wonderful! Go enjoy the weather!");
} else {
alert("Hmm. Consider staying home today.");
}
When seeking help or discussing your code:
- Provide context.
- State the coding language you're using.
- Share your code or screen.
- Explain the current behavior vs. expected behavior.
- Share any attempts you've made to solve the issue.
Example:
"On line 3 of my JS file, this function is returning undefined
, but I want it to return the sum. Do you spot any errors?"
What's a portfolio?
- A collection of work samples.
- Shows off your skills and achievements.
- Useful for job opportunities or sharing your work.
Key Features:
- Multiple HTML pages.
- Professional information about yourself.
- Links to past coding projects.
- CSS styling that matches your personality.
- JavaScript conditionals allow for decision-making in code.
- Compound conditionals help evaluate multiple conditions.
- Properly communicating about your code is essential for collaboration and debugging.
- A professional portfolio is a great tool for showcasing your skills and projects.
Remember, always refer back to this README if you need a refresher on today's topics.
Keep practicing and happy coding! 🚀