JavaScript - Learn with TumkurLab https://learnwith.tumkurlab.com Courses on web tools and technologies Thu, 16 Nov 2023 13:55:18 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 https://learnwith.tumkurlab.com/wp-content/uploads/2023/06/logo-tranparent-150x150.png JavaScript - Learn with TumkurLab https://learnwith.tumkurlab.com 32 32 Crafting a Stylish Responsive Random Quote Generator with HTML, CSS, and JavaScript https://learnwith.tumkurlab.com/crafting-a-stylish-responsive-random-quote-generator-with-html-css-and-javascript/ Sat, 28 Oct 2023 12:30:01 +0000 https://learnwith.tumkurlab.com/?p=5068 This beginner-friendly article will walk you through the process of creating a visually appealing Random Quote Generator using HTML, CSS, and JavaScript.

The post Crafting a Stylish Responsive Random Quote Generator with HTML, CSS, and JavaScript first appeared on Learn with TumkurLab.

]]>
Photo by Yathin Babu

In the world of web development, a Random Quote Generator is not just a fun project—it’s a source of inspiration and wisdom. Whether you’re building it for personal motivation or as a delightful feature for your website, this beginner-friendly guide will walk you through the process of creating a visually appealing Random Quote Generator using HTML, CSS, and JavaScript.

Setting Up the HTML Structure

Let’s begin by creating the basic HTML structure for our Random Quote Generator. We’ll have a container for the generator, a display area for quotes, and a button to trigger the randomness.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Random Quote Generator</title>
</head>
<body>
    <div class="generator">
        <div class="quote" id="quote">
            "Your random quote will appear here."
        </div>
        <button id="generate">Generate Quote</button>
    </div>
    <script src="script.js"></script>
</body>
</html>

This HTML structure lays the foundation for our Random Quote Generator, including a quote display area and a button to generate quotes.

ADVERTISEMENT

Styling with CSS

To make our Random Quote Generator visually appealing, we’ll add some CSS styles. Create a style.css file and apply the following styles:

body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    background-color: #f0f0f0;
    font-family: Arial, sans-serif;
}

.generator {
    background-color: #fff;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    width: 300px;
    text-align: center;
    padding: 20px;
}

.quote {
    font-size: 18px;
    margin-bottom: 20px;
}

button {
    border: none;
    background-color: #007BFF;
    color: #fff;
    font-size: 16px;
    padding: 10px 20px;
    cursor: pointer;
    border-radius: 5px;
}

button:hover {
    background-color: #0056b3;
}

These CSS styles give our Random Quote Generator a modern and clean appearance, ensuring it’s visually appealing.

ADVERTISEMENT

Adding JavaScript Functionality

Now, let’s infuse our Random Quote Generator with JavaScript functionality. Create a script.js file and include the following code:

// Select elements from the DOM
const quoteDisplay = document.getElementById("quote");
const generateButton = document.getElementById("generate");

// Array of random quotes
const quotes = [
    "The only limit to our realization of tomorrow will be our doubts of today. – Franklin D. Roosevelt",
    "The best way to predict the future is to create it. – Peter Drucker",
    "In the middle of every difficulty lies opportunity. – Albert Einstein",
    "Don’t watch the clock; do what it does. Keep going. – Sam Levenson",
    "You are never too old to set another goal or to dream a new dream. – C.S. Lewis",
    "The secret of getting ahead is getting started. – Mark Twain",
    // Add more quotes here
];

// Function to generate a random quote
function generateRandomQuote() {
    const randomIndex = Math.floor(Math.random() * quotes.length);
    quoteDisplay.textContent = quotes[randomIndex];
}

// Add event listener to the generate button
generateButton.addEventListener("click", generateRandomQuote);

// Generate an initial quote
generateRandomQuote();

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

ADVERTISEMENT

Making it Responsive

To ensure our Random Quote Generator is responsive, we can use media queries in our style.css file to adjust the layout for different screen sizes. Here’s an example of how you can do this:

/* Small screens (mobile) */
@media (max-width: 600px) {
    .generator {
        width: 80%;
    }
}

/* Medium screens (tablets) */
@media (min-width: 601px) and (max-width: 1024px) {
    .generator {
        width: 60%;
    }
}

/* Large screens (desktop) */
@media (min-width: 1025px) {
    .generator {
        width: 400px;
    }
}

These media queries adapt the layout of the generator for small screens (mobile), medium screens (tablets), and large screens (desktop).

Click here to get the complete source code.

Here is an article on how to host this app online using GitHub.

ADVERTISEMENT

The post Crafting a Stylish Responsive Random Quote Generator with HTML, CSS, and JavaScript first appeared on Learn with TumkurLab.

]]>
Crafting a Sleek Responsive To-Do List App with HTML, CSS, and JavaScript https://learnwith.tumkurlab.com/crafting-a-sleek-responsive-to-do-list-app-with-html-css-and-javascript/ Sat, 28 Oct 2023 12:02:41 +0000 https://learnwith.tumkurlab.com/?p=5057 Whether you're building this for personal use or as part of a larger project, this beginner-friendly article will take you through the process of creating a visually appealing To-Do List App using HTML, CSS, and JavaScript.

The post Crafting a Sleek Responsive To-Do List App with HTML, CSS, and JavaScript first appeared on Learn with TumkurLab.

]]>
Photo by Yathin Babu

In the fast-paced world we live in, staying organized is a challenge we all face. That’s where a stylish and responsive To-Do List App can come to the rescue. Whether you’re building this for personal use or as part of a larger project, this beginner-friendly article will take you through the process of creating a visually appealing To-Do List App using HTML, CSS, and JavaScript.

Setting Up the HTML Structure

Let’s kick things off by creating the basic HTML structure for our To-Do List App. We’ll have a container for the app, a section for adding tasks, a list to display tasks, and buttons for actions.

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>To-Do List App</title>
</head>
<body>
    <div class="app">
        <div class="add-task">
            <input type="text" id="task" placeholder="Add a task...">
            <button id="add">Add</button>
        </div>
        <ul id="task-list"></ul>
        <div class="actions">
            <button id="clear">Clear Completed</button>
        </div>
    </div>
    <script src="script.js"></script>
</body>
</html>

This HTML structure includes input fields for adding tasks, a list to display tasks, and buttons for actions like adding and clearing tasks.

ADVERTISEMENT

Styling with CSS

To make our To-Do List App visually appealing, let’s add some CSS styles. Create a style.css file and apply the following styles:

body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    background-color: #f0f0f0;
    font-family: Arial, sans-serif;
}

.app {
    background-color: #fff;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    width: 300px;
}

.add-task {
    padding: 10px;
    display: flex;
    border-bottom: 1px solid #ccc;
}

input {
    border: none;
    background: none;
    width: 100%;
    font-size: 14px;
    padding: 10px;
}

button {
    border: none;
    background: none;
    font-size: 14px;
    cursor: pointer;
}

#task-list {
    list-style: none;
    padding: 0;
}

li {
    border-bottom: 1px solid #ccc;
    padding: 10px;
    display: flex;
    justify-content: space-between;
}

.actions {
    padding: 10px;
    text-align: center;
}

These CSS styles give our To-Do List App a modern and clean appearance, ensuring it’s visually appealing.

ADVERTISEMENT

Adding JavaScript Functionality

Now, let’s add JavaScript functionality to our To-Do List App. Create a script.js file and include the following code:

// Select elements from the DOM
const taskInput = document.getElementById("task");
const addTaskButton = document.getElementById("add");
const taskList = document.getElementById("task-list");
const clearButton = document.getElementById("clear");

// Function to add a new task
function addTask() {
    const taskText = taskInput.value.trim();
    if (taskText === "") return;

    const taskItem = document.createElement("li");
    taskItem.innerHTML = `
        ${taskText}
        <button class="delete">Delete</button>
    `;

    taskList.appendChild(taskItem);
    taskInput.value = "";

    // Add an event listener for deleting tasks
    const deleteButton = taskItem.querySelector(".delete");
    deleteButton.addEventListener("click", () => {
        taskList.removeChild(taskItem);
    });
}

// Function to clear completed tasks
function clearCompletedTasks() {
    const completedTasks = taskList.querySelectorAll("li");
    completedTasks.forEach(task => {
        if (task.querySelector("button.delete")) {
            taskList.removeChild(task);
        }
    });
}

// Add event listeners
addTaskButton.addEventListener("click", addTask);
taskInput.addEventListener("keyup", (event) => {
    if (event.key === "Enter") {
        addTask();
    }
});
clearButton.addEventListener("click", clearCompletedTasks);

This JavaScript code adds functionality to our To-Do List App. Users can input tasks, mark them as complete, and clear completed tasks.

ADVERTISEMENT

Making it Responsive

To ensure our To-Do List App is responsive, we can use media queries in our styles.css file to adjust the layout for different screen sizes. Here’s an example of how you can do this:

/* Small screens (mobile) */
@media (max-width: 600px) {
    .app {
        width: 80%;
    }
}

/* Medium screens (tablets) */
@media (min-width: 601px) and (max-width: 1024px) {
    .app {
        width: 60%;
    }
}

/* Large screens (desktop) */
@media (min-width: 1025px) {
    .app {
        width: 400px;
    }
}

These media queries adapt the layout of the app for small screens (mobile), medium screens (tablets), and large screens (desktop).

Click here to get the complete source code.

Here is an article on how to host this app online using GitHub.

ADVERTISEMENT

The post Crafting a Sleek Responsive To-Do List App with HTML, CSS, and JavaScript first appeared on Learn with TumkurLab.

]]>
Building a Responsive Calculator with HTML, CSS, and JavaScript https://learnwith.tumkurlab.com/building-a-responsive-calculator-with-html-css-and-javascript/ Sat, 28 Oct 2023 11:36:53 +0000 https://learnwith.tumkurlab.com/?p=5050 In this step-by-step article, we'll walk you through the process of building a good-looking and responsive calculator that can perform basic operations like addition, subtraction, multiplication, and division.

The post Building a Responsive Calculator with HTML, CSS, and JavaScript first appeared on Learn with TumkurLab.

]]>
Photo by Yathin Babu

In the world of web development, creating a sleek and responsive calculator is a great way to practice your HTML, CSS, and JavaScript skills. Not only will it enhance your understanding of these technologies, but it will also result in a handy tool that you can use for everyday calculations. In this step-by-step guide, we’ll walk you through the process of building a good-looking and responsive calculator that can perform basic operations like addition, subtraction, multiplication, and division.

Setting up the HTML Structure

Let’s start by creating the basic HTML structure for our calculator. We’ll have a container for the calculator, a display for input and results, and buttons for numbers and operations.

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Responsive Calculator</title>
</head>
<body>
    <div class="calculator">
        <div class="display">
            <input type="text" id="result" value="0" readonly>
        </div>
        <div class="buttons">
            <!-- Buttons will be added here using JavaScript -->
        </div>
    </div>
    <script src="script.js"></script>
</body>
</html>

In this section, we’ve set up the basic HTML structure, including an input field for the display. The buttons for the calculator will be dynamically added using JavaScript.

ADVERTISEMENT

Styling the Calculator with CSS

Now, let’s make our calculator visually appealing by adding some CSS styles. Create a style.css file and apply the following styles. We’ll make it responsive, so it looks great on both desktop and mobile devices.

CSS:

body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    background-color: #f0f0f0;
    font-family: Arial, sans-serif;
}

.calculator {
    background-color: #fff;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    width: 300px;
}

.display {
    background-color: #333;
    color: #fff;
    padding: 10px;
    text-align: right;
}

input {
    border: none;
    background: none;
    width: 100%;
    font-size: 24px;
    color: #fff;
}

.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
}

button {
    border: none;
    background: none;
    font-size: 24px;
    padding: 10px;
    cursor: pointer;
}

These CSS styles provide a clean and modern appearance to our calculator, making it visually appealing.

ADVERTISEMENT

Adding Functionality with JavaScript

Now, it’s time to add the JavaScript functionality to our calculator. Create a script.js file and include the following code.

JS:

// Select the display input field
const display = document.getElementById("result");

// Function to update the display
function updateDisplay(value) {
    display.value = value;
}

// Function to create buttons
function createButton(label) {
    const button = document.createElement("button");
    button.textContent = label;
    return button;
}

// Add event listeners to buttons
const buttonContainer = document.querySelector(".buttons");

const buttonLabels = [
    "7", "8", "9", "/",
    "4", "5", "6", "*",
    "1", "2", "3", "-",
    "0", "C", "=", "+"
];

buttonLabels.forEach(label => {
    const button = createButton(label);
    button.addEventListener("click", () => {
        if (label === "=") {
            try {
                updateDisplay(eval(display.value));
            } catch (error) {
                updateDisplay("Error");
            }
        } else if (label === "C") {
            updateDisplay("0");
        } else {
            if (display.value === "0") {
                updateDisplay(label);
            } else {
                updateDisplay(display.value + label);
            }
        }
    });

    buttonContainer.appendChild(button);
});

This JavaScript code adds functionality to our calculator. It allows users to input numbers and perform basic operations like addition, subtraction, multiplication, and division.

ADVERTISEMENT

Making it Responsive

To make our calculator responsive, we can use media queries in our style.css file to adjust the layout for different screen sizes.

CSS:

/* Small screens (mobile) */
@media (max-width: 600px) {
    .calculator {
        width: 80%;
    }
}

/* Medium screens (tablets) */
@media (min-width: 601px) and (max-width: 1024px) {
    .calculator {
        width: 60%;
    }
}

/* Large screens (desktop) */
@media (min-width: 1025px) {
    .calculator {
        width: 400px;
    }
}

These media queries will adapt the calculator’s layout for small screens (mobile), medium screens (tablets), and large screens (desktop).

Conclusion

Congratulations! You’ve successfully built a responsive and good-looking calculator using HTML, CSS, and JavaScript. This project allows you to apply various JavaScript concepts like event handling, DOM manipulation, and conditional statements in a practical way. Whether you’re a beginner or an experienced developer, creating such projects is a great way to sharpen your coding skills and have a handy tool at your disposal.

Feel free to enhance your calculator by adding more features like percentage calculations or scientific functions. The possibilities are endless, and it’s a fantastic way to keep improving your web development skills. Happy coding!

Click here to get the complete source code.

Here is an article on how to host this app online using GitHub.

ADVERTISEMENT

The post Building a Responsive Calculator with HTML, CSS, and JavaScript first appeared on Learn with TumkurLab.

]]>