const multilineString = "First line\n" +
    "Second line\n" +
    "Third line";
    
console.log(multilineString);
// Output:
// "First line"
// "Second line"
// "Third line"
const multilineString = `First line
    Second line
    Third line`;

console.log(multilineString);
// Output:
// "First line"
// "Second line"
// "Third line"
let name = "John Doe";
const message = "Welcome, " + name + "!";
console.log(message);
// Output: "Welcome, John Doe!"
let name = "John Doe";
const message = `Welcome, ${name}!`;
console.log(message);
// Output: "Welcome, John Doe!"
const x = 10;
const y = 5;
const result = `${x} + ${y} = ${x + y}`;
console.log(result);
// Output: 10 + 5 = 15

function greet(name) {
    return `Hello, ${name}!`;
}

const userName = "John";
const message = `Greeting message: ${greet(userName)}`;
console.log(message);
// Output: "Greeting message: Hello, John!"
const person = {
    name: "John",
    age: 30,
    greet() {
    return `Hello, I am ${this.name}, and I am ${this.age} years old.`;
    }
};

const greeting = person.greet();
console.log(greeting);
// Output: "Hello, I am John, and I am 30 years old."
const fruits = ["Apple", "Banana", "Orange"];
const message = `My favorite fruits are ${fruits[0]}, ${fruits[1]}, and ${fruits[2]}.`;
console.log(message);
// Output: "My favorite fruits are Apple, Banana, and Orange."
const baseURL = "https://api.example.com";

// 1. Basic usage of template literals for URLs
const endpoint1 = `${baseURL}/users`;
console.log(endpoint1); // Output: "https://api.example.com/users"

// 2. Inserting variables into URLs
const userId = 123;
const endpoint2 = `${baseURL}/users/${userId}`;
console.log(endpoint2); // Output: "https://api.example.com/users/123"

// 3. Handling URL parameters
const postId = 456;
const endpoint3 = `${baseURL}/users/${userId}/posts/${postId}`;
console.log(endpoint3); // Output: "https://api.example.com/users/123/posts/456"

// 4. Generating query strings
const params = {
    category: "books",
    limit: 10,
    sort: "desc"
};
const queryString = Object.entries(params)
  .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
  .join("&");
const endpoint4 = `${baseURL}/search?${queryString}`;
console.log(endpoint4); // Output: "https://api.example.com/search?category=books&limit=10&sort=desc"
// 1. Basic HTML template literal usage
const title = "Welcome!";
const content = "Hello, world!";
const htmlTemplate1 = `
    <div class="container">
        <h1>${title}</h1>
        <p>${content}</p>
    </div>
`;

console.log(htmlTemplate1);

// 2. Inserting dynamic data
const user = {
    name: "John",
    age: 30,
    email: "john@example.com"
};
const htmlTemplate2 = `
    <div class="user-profile">
        <h2>${user.name}</h2>
        <p>Age: ${user.age}</p>
        <p>Email: ${user.email}</p>
    </div>
`;

console.log(htmlTemplate2);

// 3. Creating lists with loops
const todos = [
    {id: 1, title: "Buy groceries"},
    {id: 2, title: "Do laundry"},
    {id: 3, title: "Clean the house"}
];
const todoList = `
    <ul>
        ${todos.map(todo => `<li>${todo.title}</li>`).join("")}
    </ul>
`;
console.log(todoList);

// 4. Generating dynamic HTML with conditionals
const isAuthenticated = true;
const loginMessage = `
    ${isAuthenticated ? `<p>Welcome back, ${user.name}!</p>` : `<p>Please log in.</p>`}
`;

console.log(loginMessage);
// 1. Basic log message using template literals
const message1 = "Something happened";
console.log(`[INFO] ${message1}`);

// 2. Adding log level and timestamp
function formatLog(level, message) {
    const timestamp = new Date().toLocaleString();
    return `[${level}] ${timestamp} - ${message}`;
}

const message2 = "An error occurred";
console.log(formatLog("ERROR", message2));

// 3. Inserting dynamic data into logs
function formatLog(level, message, data) {
    const timestamp = new Date().toLocaleString();
    return `[${level}] ${timestamp} - ${message} - ${JSON.stringify(data)}`;
}

const user = {id: 123, name: "John"};
console.log(formatLog("DEBUG", "User logged in", user));