Turning Learners Into Developers
Codekilla
CODEKILLA
// projects.javascript

10 Best JavaScript Projects

Hand-picked and ordered easiest → hardest — each with complete code and expected output. Build these to turn lessons into a portfolio.

Back to JavaScript course
// solution.code
javascript
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Personal Greeting Card</title>
    <style>
        body { font-family: Arial, sans-serif; text-align: center; padding: 50px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; }
        #greeting { font-size: 2em; margin-top: 30px; padding: 20px; background: rgba(255,255,255,0.1); border-radius: 10px; }
    </style>
</head>
<body>
    <h1>Welcome to Your Personal Greeting Card</h1>
    <button id="greetBtn" onclick="generateGreeting()">Click to Get Your Greeting</button>
    <div id="greeting"></div>

    <script>
        // Function to generate personalized greeting
        function generateGreeting() {
            // Prompt user for their name
            const userName = prompt("Please enter your name:");
            
            // Check if user provided a name
            if (userName === null || userName.trim() === "") {
                alert("Please enter a valid name!");
                return;
            }
            
            // Get current date and format it
            const currentDate = new Date();
            const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
            const formattedDate = currentDate.toLocaleDateString('en-US', options);
            
            // Create personalized greeting message using string concatenation
            const greetingMessage = "Hello, " + userName + "! 🎉<br>" +
                                   "Welcome to this special day!<br>" +
                                   "Today is " + formattedDate;
            
            // Display greeting in the DOM
            document.getElementById('greeting').innerHTML = greetingMessage;
        }
    </script>
</body>
</html>
output
When the user clicks the button and enters a name (e.g., 'Sarah'), the page displays: 'Hello, Sarah! 🎉 Welcome to this special day! Today is [current date in format like 'Monday, January 15, 2024']' in a styled box with gradient purple background.