Web Development - HTML, CSS & JavaScript
55.6K subscribers
1.91K photos
5 videos
34 files
531 links
Learn to code and become a Web Developer with HTML, CSS, JavaScript , Reactjs, Wordpress, PHP, Mern & Nodejs knowledge

Managed by: @love_data
Download Telegram
Double Tap ❤️ For Part-4
❤4
🚀 𝗠𝗜𝗖𝗥𝗢𝗦𝗢𝗙𝗧 + 𝗟𝗜𝗡𝗞𝗘𝗗𝗜𝗡 𝗙𝗥𝗘𝗘 𝗖𝗢𝗨𝗥𝗦𝗘𝗦! 🎓🔥

😍 Explore 5 FREE Career Learning Paths to boost your resume!

📊 Data Analytics | ☁️ Cloud Computing | 🤖 AI | 🔐 Cybersecurity | 💻 Software Development

✅ Learn In-Demand Skills
✅ Explore Certificate Opportunities
✅ Perfect for Students, Freshers & Job Seekers

🔗 𝗟𝗶𝗻𝗸 :- 👇

https://pdlink.in/4eOufX9

📲 Share with your friends! 🔥
❤2
💻 JavaScript Learning Series - Day 4

Topic 4: Conditional Statements in JavaScript

Conditional statements allow a program to make decisions based on whether a condition is true or false.

For example:

• Check whether a person is eligible to vote.
• Check whether a student has passed or failed.
• Verify login credentials.
• Apply discounts based on purchase amounts.

1. The if Statement

The
if

statement executes a block of code only when a condition is true.

Syntax:
if (condition) {
    // Code executes if condition is true
}

Example:
let age = 20;

if (age >= 18) {
    console.log("You are eligible to vote");
}

Output: You are eligible to vote

2. The if-else Statement

Executes one block when the condition is true and another when it is false.
let age = 16;

if (age >= 18) {
    console.log("Eligible to vote");
} else {
    console.log("Not eligible to vote");
}

Output: Not eligible to vote

3. The else-if Statement

Used when you need to check multiple conditions.

Example: Student Grading System
let marks = 85;

if (marks >= 90) {
    console.log("Grade A");
} else if (marks >= 75) {
    console.log("Grade B");
} else if (marks >= 60) {
    console.log("Grade C");
} else if (marks >= 40) {
    console.log("Grade D");
} else {
    console.log("Fail");
}

Output: Grade B

4. Nested if Statements

An
if

statement inside another
if

statement is called a nested
if

statement.

Example: Login Verification
let username = "admin";
let password = "12345";

if (username === "admin") {
    if (password === "12345") {
        console.log("Login Successful");
    } else {
        console.log("Incorrect Password");
    }
} else {
    console.log("Invalid Username");
}

Output: Login Successful

5. The switch Statement

Used when you want to compare one expression against multiple possible values.
switch (expression) {
    case value1:
        // Code
        break;

    case value2:
        // Code
        break;

    default:
        // Default code
}

Example: Day of the Week
let day = 3;

switch (day) {
    case 1:
        console.log("Monday");
        break;

    case 2:
        console.log("Tuesday");
        break;

    case 3:
        console.log("Wednesday");
        break;

    default:
        console.log("Invalid Day");
}

Output: Wednesday

Remember:

•
case

defines possible matching values.
•
break

prevents execution from falling through to the next case.
•
default

executes when no case matches.

6. Ternary Operator

A shorter way to write a simple if-else condition.
condition ? expression1 : expression2;

let age = 21;

let result = age >= 18
    ? "Adult"
    : "Minor";

console.log(result);

Output:
Adult

7. Multiple Conditions Using Logical Operators

AND (&&)

Both conditions must be true.
let age = 25;
let hasLicense = true;

if (age >= 18 && hasLicense) {
    console.log("You can drive");
}

OR (||)

At least one condition must be true.
let isWeekend = false;
let isHoliday = true;

if (isWeekend || isHoliday) {
    console.log("It's a day off");
}

NOT (!)

Reverses a Boolean condition.
let isLoggedIn = false;

if (!isLoggedIn) {
    console.log("Please log in");
}

8. Real-World Example: Online Shopping Discount
let purchaseAmount = 5000;
let discount = 0;

if (purchaseAmount >= 5000) {
    discount = 20;
} else if (purchaseAmount >= 3000) {
    discount = 10;
} else if (purchaseAmount >= 1000) {
    discount = 5;
}

let finalAmount =
    purchaseAmount - (purchaseAmount * discount / 100);

console.log("Purchase:", purchaseAmount);
console.log("Discount:", discount + "%");
console.log("Final Amount:", finalAmount);

Output:
Purchase: 5000
Discount: 20%
Final Amount: 4000
9. Types of Conditional Statements

🔹 if ➜ Checks one condition.

🔹 if-else ➜ Chooses between two possible paths.

🔹
else-if

➜ Checks multiple conditions.

🔹 Nested if ➜ Checks dependent conditions inside another condition.

🔹 switch ➜ Matches an expression against multiple possible values.

Double Tap ❤️ For Part-5
❤6
🎓 𝟰 𝗖𝗲𝗿𝘁𝗶𝗳𝗮𝘁𝗶𝗼𝗻𝘀 𝗧𝗼 𝗠𝗮𝘀𝘁𝗲𝗿 𝗜𝗻 𝟮𝟬𝟮𝟲 🚀

Want to build job-ready skills and strengthen your resume? Start learning these in-demand technologies

📊 𝗗𝗮𝘁𝗮 𝗔𝗻𝗮𝗹𝘆𝘁𝗶𝗰𝘀 :- https://pdlink.in/45vk5ph

💫 𝗙𝘂𝗹𝗹𝘀𝘁𝗮𝗰𝗸 :- https://pdlink.in/3SuUeuD

☁️ 𝗗𝗮𝘁𝗮 𝗦𝗰𝗶𝗲𝗻𝗰𝗲 :- :- https://pdlink.in/48kyZjt

🛡️ 𝗔𝗜 𝗘𝗻𝗴𝗶𝗻𝗲𝗲𝗿𝗶𝗻𝗴 :- :- https://pdlink.in/4fWJVID

🔁 𝗦𝗵𝗮𝗿𝗲 this with your friends and classmates!