May 28, 10:52pm

To load the word list on page load, you can use JavaScript to populate the textarea with the predefined word list when the page loads. Here's how you can modify the HTML page to achieve this:

html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Number-Word Converter</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        textarea, input {
            width: 100%;
            padding: 8px;
            margin: 5px 0 15px;
            display: inline-block;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 15px;
            margin: 8px 0;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background-color: #45a049;
        }
        .container {
            border-radius: 5px;
            background-color: #f2f2f2;
            padding: 20px;
        }
    </style>
</head>
<body onload="loadWordList()">
    <div class="container">
        <h2>Number-Word Converter</h2>
        <label for="wordList">Word List (JSON Array):</label>
        <textarea id="wordList" rows="4"></textarea>

        <h3>Convert Numbers to Words</h3>
        <label for="numbers">Numbers (comma-separated):</label>
        <input type="text" id="numbers" placeholder="Enter numbers">
        <button onclick="convertNumbersToWords()">Convert to Words</button>
        <p id="numbersResult"></p>

        <h3>Convert Words to Numbers</h3>
        <label for="words">Words (space-separated):</label>
        <input type="text" id="words" placeholder="Enter words">
        <button onclick="convertWordsToNumbers()">Convert to Numbers</button>
        <p id="wordsResult"></p>
    </div>

    <script>
        let wordList = [
            "Apple", "Banana", "Cherry", "Orange", "Mango", "Grapes", "Watermelon", "Strawberry",
            "Blueberry", "Raspberry", "Pineapple", "Peanut", "Butter", "Sugar", "Coffee",
            "Chocolate", "Vanilla", "Biscuit", "Scone", "Sandwich", "Hamburger", "Pizza",
            "Spaghetti", "Lasagne", "Taco", "Burrito", "Sushi", "Pancake", "Waffle", "Omelette",
            "Salad", "Soup", "Steak", "Chicken", "Turkey", "Duck", "Pasta", "Rice", "Bread",
            "Toast", "Jam", "Jelly", "Honey", "Syrup", "Cereal", "Porridge", "Yoghurt", "Milkshake",
            "Smoothie", "Lemonade", "Juice", "Soda", "Tea", "Milk", "Cheese", "Cracker", "Pretzel",
            "Popcorn", "Peanut Butter", "Jellybean", "Lollipop", "Cupcake", "Muffin", "Doughnut",
            "Bagel", "Croissant", "Tiramisu", "Brownie", "Caramel", "Marshmallow", "Pudding",
            "Custard", "Fudge", "Toffee", "Liquorice", "Gumdrop", "Macaroon", "Baguette", "Ciabatta",
            "Focaccia", "Pita", "Tortilla", "Dumpling", "Noodle", "Ravioli", "Calzone", "Quiche",
            "Soufflé", "Flan", "Gelato", "Sorbet", "Parfait", "Sundae", "Frappé", "Latte",
            "Cappuccino", "Espresso", "Mocha", "Chai", "Biscotti", "Cucumber", "Tomato", "Potato",
            "Lettuce", "Cabbage", "Broccoli", "Carrot", "Onion", "Garlic", "Pepper", "Spinach",
            "Pumpkin", "Cauliflower", "Beetroot", "Radish", "Turnip", "Sweetcorn", "Peas", "Beans",
            "Lentils", "Chickpea", "Aubergine", "Courgette", "Celery", "Asparagus", "Artichoke",
            "Brussels Sprout", "Leek", "Shallot", "Spring Onion", "Mushroom", "Truffle", "Avocado",
            "Coconut", "Pomegranate", "Kiwi", "Pear", "Peach", "Plum", "Apricot", "Nectarine",
            "Fig", "Date", "Melon", "Lime", "Lemon", "Clementine", "Tangerine", "Grapefruit",
            "Cranberry", "Blackberry", "Elderberry", "Gooseberry", "Boysenberry", "Cloudberry",
            "Dewberry", "Loganberry", "Mulberry", "Salmon", "Tuna", "Cod", "Haddock", "Mackerel",
            "Sardine", "Herring", "Trout", "Anchovy", "Carp", "Catfish", "Swordfish", "Monkfish",
            "Plaice", "Halibut", "Turbot", "Sea Bass", "Red Snapper", "Mahi-Mahi", "Grouper",
            "Lobster", "Crab", "Shrimp", "Prawn", "Scallop", "Mussel", "Oyster", "Clam", "Squid",
            "Octopus", "Eel", "Caviar", "Almond", "Walnut", "Cashew", "Pistachio", "Hazelnut",
            "Pecan", "Macadamia", "Brazil Nut", "Pine Nut", "Chestnut", "Sunflower Seed",
            "Pumpkin Seed", "Sesame Seed", "Flaxseed", "Chia Seed", "Quinoa", "Barley", "Oats",
            "Rye", "Millet", "Buckwheat", "Farro", "Bulghur", "Couscous", "Polenta", "Semolina",
            "Amaranth", "Wild Rice", "Basin", "Basket", "Bottle", "Bowl", "Bucket", "Candle",
            "Carpet", "Curtain", "Cushion", "Lamp", "Mirror", "Painting", "Picture", "Pillow",
            "Plate", "Pot", "Rug", "Shelf", "Soap", "Statue", "Table", "Towel", "Vase", "Blanket",
            "Clock", "Coat", "Dress", "Glove", "Hat", "Jacket", "Jeans", "Jumper", "Scarf",
            "Shirt", "Shoe", "Skirt", "Sock", "Tie", "T-shirt", "Trousers", "Umbrella", "Belt",
            "Boot", "Cap", "Cardigan", "Coat", "Dressing Gown", "Earring", "Glasses", "Handbag",
            "Necklace", "Pyjamas", "Ring", "Sandals", "Sunglasses", "Sweater", "Tights", "Trainers",
            "Wallet", "Watch", "Bracelet", "Brooch", "Backpack", "Briefcase", "Camera", "Compass",
            "Diary", "Flask", "Headphones", "Journal", "Key", "Lighter", "Map", "Notebook", "Pen",
            "Pencil", "Phone", "Radio", "Tape", "Torch", "Tripod", "Walkman", "Binoculars",
            "Calculator", "Calendar", "Compass", "Drill", "Hammer", "Ladder", "Level", "Pliers",
            "Saw", "Screwdriver", "Shovel", "Spade", "Tape Measure", "Toolbox", "Wrench", "Broom",
            "Brush", "Duster", "Hoover", "Mop", "Sponges", "Bucket", "Bicycle", "Car", "Bus",
            "Train", "Plane", "Boat", "Ship", "Truck", "Van", "Motorcycle", "Scooter", "Tractor",
            "Helicopter", "Submarine", "Rocket", "Skateboard", "Sled", "Stroller", "Wheelchair",
            "Balloon", "Kite", "Parachute", "Raft", "Sailboat", "Surfboard", "Unicycle", "Wagon",
            "Yacht", "Zeppelin", "Ambulance", "Canoe", "Glider", "Hovercraft", "Jet Ski", "Rickshaw",
            "Skis", "Snowboard", "Space Shuttle", "Tank", "Taxi", "Tram", "Ball", "Bat", "Club",
            "Dart", "Golf", "Hockey", "Puck", "Racket", "Shuttlecock", "Table Tennis", "Tennis",
            "Volleyball", "Basketball", "Football", "Baseball", "Cricket", "Rugby", "Badminton",
            "Squash", "Pool", "Snooker", "Darts", "Bowling", "Curling", "Fencing", "Archery",
            "Boxing", "Wrestling", "Judo", "Karate", "Taekwondo", "Sumo", "Weightlifting",
            "Gymnastics", "Athletics", "Cycling", "Swimming", "Diving", "Synchronized Swimming",
            "Water Polo", "Rowing", "Canoeing", "Sailing", "Equestrian", "Pentathlon", "Heptathlon",
            "Decathlon", "Triathlon", "Marathon", "Sprint", "Hurdles", "Relay", "Long Jump",
            "High Jump", "Pole Vault", "Shot Put", "Discus", "Hammer Throw", "Javelin", "Biathlon",
            "Cross-Country Skiing", "Ice Hockey", "Figure Skating", "Speed Skating", "Bobsleigh",
            "Luge", "Skeleton", "Snowboarding", "Freestyle Skiing", "Alpine Skiing", "Nordic Combined",
            "Ski Jumping", "Band", "Choir", "Orchestra", "Singer", "Guitar", "Piano", "Violin",
            "Drum", "Flute", "Trumpet", "Saxophone", "Clarinet", "Trombone", "Cello", "Harp",
            "Accordion", "Banjo", "Harmonica", "Xylophone", "Tambourine", "Triangle", "Viola",
            "Double Bass", "French Horn", "Tuba", "Oboe", "Bassoon", "Piccolo", "Conductor",
            "Composer", "Lyricist", "Producer", "Director", "Actor", "Actress", "Dancer",
            "Choreographer", "Screenwriter", "Cinematographer", "Editor", "Makeup Artist",
            "Costume Designer", "Set Designer", "Sound Engineer", "Lighting Technician",
            "Stage Manager", "Cameraman", "Stuntman", "Author", "Poet", "Novelist", "Playwright",
            "Journalist", "Reporter", "Editor", "Columnist", "Critic", "Blogger", "Illustrator",
            "Cartoonist", "Photographer", "Painter", "Sculptor", "Architect", "Designer",
            "Potter", "Weaver", "Blacksmith", "Goldsmith", "Silversmith", "Carpenter", "Mason",
            "Glazier", "Plumber", "Electrician", "Mechanic", "Tailor", "Cobbler", "Baker",
            "Butcher", "Chef", "Brewer", "Vintner", "Farmer", "Gardener", "Florist", "Landscaper",
            "Forester", "Fisherman", "Hunter", "Miner", "Jeweller", "Watchmaker", "Bookbinder",
            "Printer", "Publisher", "Librarian", "Curator", "Archaeologist", "Astronomer",
            "Biologist", "Chemist", "Physicist", "Geologist", "Meteorologist", "Paleontologist",
            "Psychologist", "Sociologist", "Anthropologist", "Economist", "Historian", "Linguist",
            "Philosopher", "Theologian", "Mathematician", "Statistician", "Engineer", "Programmer",
            "Analyst", "Technician", "Scientist", "Researcher", "Professor", "Teacher", "Lecturer",
            "Tutor", "Instructor", "Coach", "Trainer", "Mentor", "Advisor", "Consultant",
            "Counsellor", "Therapist", "Doctor", "Nurse", "Surgeon", "Dentist", "Pharmacist",
            "Veterinarian", "Optician", "Audiologist", "Chiropractor", "Physiotherapist",
            "Podiatrist", "Psychiatrist", "Radiographer", "Paramedic", "Midwife", "Dietitian",
            "Nutritionist", "Speech Therapist", "Occupational Therapist", "Social Worker",
            "Caregiver", "Attendant", "Warden", "Guard", "Police Officer", "Detective", "Sheriff",
            "Marshal", "Soldier", "Sailor", "Pilot", "Captain", "Admiral", "General", "Colonel",
            "Major", "Lieutenant", "Sergeant", "Corporal", "Private", "Cadet", "Recruit", "Veteran",
            "Firefighter", "Lifeguard", "Rescuer", "Volunteer", "Donor", "Philanthropist",
            "Sponsor", "Ambassador", "Diplomat", "Mayor", "Governor", "Senator", "Representative",
            "Minister", "Secretary", "President", "Vice President", "Chancellor", "Premier",
            "Monarch", "Prince", "Princess", "Duke", "Duchess", "Earl", "Countess", "Baron",
            "Baroness", "Lord", "Lady", "Sir", "Dame", "Knight", "Esquire", "Citizen", "Resident",
            "Immigrant", "Emigrant", "Tourist", "Traveller", "Explorer", "Pioneer", "Settler",
            "Nomad", "Refugee", "Student", "Pupil", "Graduate", "Alumnus", "Scholar", "Fellow",
            "Intern", "Apprentice", "Trainee", "Employee", "Employer", "Manager", "Supervisor",
            "Director", "Executive", "Entrepreneur", "Businessman", "Businesswoman", "Investor",
            "Partner", "Colleague", "Assistant", "Secretary", "Clerk", "Accountant", "Auditor",
            "Banker", "Economist", "Analyst", "Consultant", "Marketer", "Salesperson", "Retailer",
            "Wholesaler", "Trader", "Merchant", "Shopkeeper", "Vendor", "Customer", "Client",
            "Consumer", "User", "Subscriber", "Member", "Participant", "Attendee", "Guest",
            "Host", "Organiser", "Planner", "Coordinator", "Facilitator", "Moderator", "Speaker",
            "Presenter", "Performer", "Artist", "Musician", "Dancer", "Actor", "Comedian",
            "Magician", "Clown", "Acrobat", "Juggler", "Mime", "Puppeteer", "Ventriloquist",
            "Hypnotist", "Illusionist", "Escapologist", "Stunt Performer"
        ];

        function loadWordList() {
            document.getElementById('wordList').value = JSON.stringify(wordList, null, 2);
        }

        function encodeNumberToWords(numberStr) {
            const paddedNumberStr = numberStr.padStart(12, '0');
            const triplets = paddedNumberStr.match(/.{1,3}/g) || [];
            return triplets.map(triplet => {
                const tripletInt = parseInt(triplet, 10);
                return tripletInt < wordList.length ? wordList[tripletInt] : triplet;
            }).join(' ');
        }

        function decodeWordsToNumber(encodedStr) {
            const wordToNum = wordList.reduce((acc, word, idx) => {
                acc[word] = String(idx).padStart(3, '0');
                return acc;
            }, {});

            const words = encodedStr.split(' ');
            const triplets = words.map(word => wordToNum[word] || word.padStart(3, '0'));
            return triplets.join('').replace(/^0+/, '') || '0';
        }

        function convertNumbersToWords() {
            const numbersInput = document.getElementById('numbers').value;
            const numbers = numbersInput.split(',').map(num => num.trim());
            const results = numbers.map(encodeNumberToWords);
            document.getElementById('numbersResult').innerText = results.join(', ');
        }

        function convertWordsToNumbers() {
            const wordsInput = document.getElementById('words').value;
            const result = decodeWordsToNumber(wordsInput);
            document.getElementById('wordsResult').innerText = result;
        }
    </script>
</body>
</html>

Explanation:

  • JavaScript Array: The wordList array contains the predefined list of words.
  • loadWordList Function: This function is called when the page loads (onload="loadWordList()"). It populates the textarea with the JSON string representation of the wordList.
  • Encoding and Decoding Functions: These functions remain the same as before, using the wordList for conversion.

This setup ensures that the word list is loaded into the textarea as soon as the page is opened.

May 28, 10:52pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more