🚀 JavaScript Problems - Complete Solution

1. Arrow Functions

Problem 1.1 - Function Conversion

// Arrow Functions: const square = num => num * num; const greet = name => `Hello, ${name}`;

Problem 1.2 - Using Arrow Functions with Array Methods

let numbers = [2, 4, 6, 8]; let doubled = numbers.map(num => num * 2); console.log(doubled); // [4, 8, 12, 16]

2. Callback Functions

Problem 2.1 - Execute a Callback

function greetUser(name, callback) { console.log(`Welcome, ${name}!`); callback(); } greetUser("Palak", () => console.log("Callback executed!"));

Problem 2.2 - Custom Array Processor

function processArray(arr, callback) { let result = []; for (let i = 0; i < arr.length; i++) { result.push(callback(arr[i])); } return result; } console.log(processArray([1, 2, 3], num => num * 10)); // [10, 20, 30]

3. Promises

Problem 3.1 - Simple Promise Handling

function loadData() { return new Promise(resolve => { setTimeout(() => resolve("Data Loaded"), 2000); }); } loadData().then(console.log);

Problem 3.2 - Simulate an API Call

function fakeFetch(url) { return new Promise(resolve => { setTimeout(() => resolve(`Data fetched from ${url}`), 3000); }); } fakeFetch("https://api.example.com").then(console.log);

4. DOM Manipulation

Problem 4.1 - Change HTML Content

This is a paragraph.

Problem 4.2 - Dynamic List Items

    5. Events

    Problem 5.1 - Button Click Event

    Problem 5.2 - Keyboard Input Display

    Start typing to see text appear here...