Monster Manager

Technologies used -
Description

Monster Manager is a simple yet interactive web application built using HTML, CSS, and JavaScript. It allows users to create and manage a list of monsters by specifying their details. The application provides an easy way to add, view, and delete monsters dynamically.

Features:

  • Users can enter the monster’s name.
  • Users can select the rarity of the monster from a dropdown list.
  • Users can mark the monster as a favorite using a checkbox.
  • Clicking the “Create” button adds the monster to a dynamic table displayed at the bottom.
  • The table includes Name, Rarity, Favorite status, and a Delete button.
  • Users can remove a monster from the list by clicking the “Delete” button.
Highlighted Source Code
				
					function createMonster(event) {
    event.preventDefault(); // Prevents the default form submission behavior

    // Getting all input field values
    const name = document.getElementById('name').value;
    const type = document.querySelector('input[name="type"]:checked'); // Gets the selected radio button
    const rarity = document.getElementById('rarity').value;
    const favorite = document.querySelector('input[name="favorite"]').checked; // Checks if the checkbox is checked

    // Validating the form to ensure all required fields are filled
    if (!name || !type || !rarity) {
        alert('Please fill out all fields.');
        return;
    }

    // Creating a monster object with the collected values
    const monster = {
        name,
        type: type.value, // Extracts the selected radio button's value
        rarity,
        favorite
    };

    // Calls function to add the monster details to the table
    addMonsterToTable(monster);

    // Resets the form fields after submission
    document.getElementById('monster-form').reset();
}

// Function to display the monster details in a table format
function addMonsterToTable(monster) {
    const tableBody = document.getElementById('monster-table-body'); // Gets the table body
    const row = tableBody.insertRow(); // Creates a new row in the table

    // Populating the row with monster details
    row.innerHTML = `
        <td>${monster.favorite ? 'Yes' : 'No'}</td> <!-- Shows 'Yes' if favorite is true, otherwise 'No' -->
        <td>${monster.name}</td>
        <td>${monster.type}</td>
        <td>${monster.rarity}</td>
        <td><button class="delete-btn">Delete</button></td> <!-- Delete button -->
    `;
}

// Function to delete a monster entry from the table
function deleteMonster(button) {
    const row = button.parentElement.parentElement; // Gets the parent row of the clicked button
    row.remove(); // Removes the row from the table
}

				
			

Related Projects

Fun Project

Tic Tac Toe Game

The Interactive Tic Tac Toe Game lets two players compete in a 3×3 grid. It includes a simple interface, feedback on wins, and sound effects for added fun.

Read More »
Form & Input Handling

Text-to-Speech Converter

This Text-to-Speech app lets you type text and listen to it spoken aloud in different voices. Choose a voice, click ‘Listen,’ and hear the text in real-time.

Read More »