Skip to main content

Featured

🔠 Day 8 — Strings & String Methods in JavaScript

🔠 Day 8 — Strings & String Methods in JavaScript Welcome to Day 8 🌟 — Today’s session is all about **Strings**, one of the most common data types in JavaScript. Strings represent text and allow you to store names, messages, or any sequence of characters. 💬 1️⃣ What is a String? A string is a sequence of characters written inside quotes. let name = "Rahul"; let greeting = 'Hello World'; let message = `Welcome ${name}!`; // Template literal 🧩 2️⃣ String Properties Strings behave like arrays — they have a .length property and can be accessed using index numbers. let text = "JavaScript"; console.log(text.length); // 10 console.log(text[0]); // J console.log(text[text.length - 1]); // t 🎨 3️⃣ Common String Methods toUpperCase() & toLowerCase() let city = "Hyderabad"; console.log(city.toUpperCase()); console.log(city.toLowerCase()); slice(start, end) let word = "JavaScript"; console.log(word.slice(0, 4)...

🔁 Day 4 — Conditional Statements (if, else, switch)

🔁 Day 4 — Conditional Statements (if, else, switch)

Welcome to Day 4 🚀 Today we learn how to make your programs **smart** — to think, decide, and act based on conditions. Conditional statements help you execute different code blocks depending on whether something is true or false.

⚙️ 1️⃣ The if Statement

The if statement checks a condition. If it’s true, the code inside runs.

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

🔄 2️⃣ if...else

Use else when you want to run one block if true, another if false.

let age = 16;
if (age >= 18) {
  console.log("You can vote.");
} else {
  console.log("Sorry, you are too young to vote.");
}

🔁 3️⃣ if...else if...else

Used for multiple conditions.

let marks = 85;

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

🔀 4️⃣ switch Statement

The switch statement is a cleaner way to handle multiple conditions based on one variable.

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");
}

🧩 5️⃣ Ternary Operator

A short way to write if...else in one line.

let age = 20;
let message = (age >= 18) ? "Adult" : "Minor";
console.log(message);

🧠 6️⃣ Practice Task

  1. Write a program to check if a number is positive, negative, or zero.
  2. Use switch to print the month name for a given number.
  3. Create a ternary expression to check if a person can drive (age ≥ 18).

🎯 Summary

Today, you learned how to control your program’s logic with conditions. Tomorrow, you’ll move into **Loops** — where your program starts repeating intelligently.

Comments