<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise Exercise - Odd/Even Number</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 700px;
            margin: 50px auto;
            padding: 20px;
            background: linear-gradient(to bottom, #e3f2fd, #fff3e0);
        }
        .container {
            border: 3px solid #1976d2;
            padding: 30px;
            border-radius: 10px;
            background-color: white;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
        h1 {
            color: #1976d2;
            text-align: center;
        }
        button {
            padding: 15px 30px;
            margin: 20px 10px;
            font-size: 18px;
            cursor: pointer;
            border-radius: 8px;
            border: none;
            color: white;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            transition: transform 0.2s;
        }
        button:hover {
            transform: scale(1.05);
        }
        button:active {
            transform: scale(0.98);
        }
        .button-container {
            text-align: center;
        }
        #output {
            margin-top: 30px;
            padding: 20px;
            border-radius: 8px;
            min-height: 50px;
            font-size: 18px;
            font-weight: bold;
        }
        .success {
            background-color: #d4edda;
            color: #155724;
            border: 2px solid #c3e6cb;
        }
        .error {
            background-color: #f8d7da;
            color: #721c24;
            border: 2px solid #f5c6cb;
        }
        .info {
            background-color: #d1ecf1;
            color: #0c5460;
            border: 2px solid #bee5eb;
            font-style: italic;
        }
        .note {
            margin-top: 20px;
            padding: 15px;
            background-color: #fff3cd;
            border-left: 4px solid #ffc107;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🎲 Promise Exercise: Odd/Even Number Generator</h1>
        
        <div class="info" style="padding: 15px; margin-bottom: 20px;">
            <strong>How it works:</strong><br>
            • Generates a random number between 0 and 10<br>
            • If the number is odd → Success (Promise resolves)<br>
            • If the number is even → Error (Promise rejects)<br>
        </div>

        <div class="button-container">
            <button id="generateBtn">Generate Random Number</button>
            <button onclick="ReadNumber()">Test Async/Await</button>
        </div>

        <div id="output"></div>

        <div class="note">
            <strong>Note:</strong> Math.random() produces a value ≥ 0 and < 1. 
            Math.floor() rounds down, so the result is a random value between 0 and 10.
        </div>
    </div>

    <!-- Link JavaScript files in order here -->
    <script src="create-promise.js"></script>
    <script src="using-promise.js"></script>
    <script>
        // Main execution when button is clicked
        document.getElementById('generateBtn').addEventListener('click', function() {
            const outputDiv = document.getElementById('output');
            
            // Show processing state
            outputDiv.textContent = '🔄 Generating random number...';
            outputDiv.className = 'info';
            
            // Call the promise (defined in createpromise.js)
            let promise = SomeAsyncFunction();
            
            // Handle the promise using callbacks from usingpromise.js
            promise.then(onResolveCallback, onRejectCallback);
        })

        // Optional: Auto-run on page load
        window.addEventListener('load', function() {
            document.getElementById('output').textContent = 'Click the button to generate a random number and test the promise!';
            document.getElementById('output').className = 'info';

            // document.getElementById('asyncOutput').textContent = 'Click the button to test Async/Await method!';
            // document.getElementById('asyncOutput').className = 'info';
        });
    </script>
</body>
</html>