mqxym

char_randomizer_v1_2.html

May 27th, 2024 (edited)
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.16 KB | Source Code | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <!-- This was one of my first javascript projects :) -->
  4.     <head>
  5.         <meta charset="UTF-8">
  6.         <title>Char Randomizer 1.2</title>
  7.     </head>
  8.    
  9.     <body>
  10.         <b>Enter some text:</b>
  11.         <br><br>
  12.         <section>
  13.             <form>
  14.                 <textarea rows="10" cols="30" id="textInput" >Welcome to the Randomizer 1.2!</textarea><br>
  15.                 <input type="button" onclick="randomizeChars()" value="Randomiue!">
  16.             </form>
  17.         </section>
  18.         <section>
  19.         <br>
  20.         <h3>Result:</h3>
  21.             <textarea type="text" id="textOutput" readonly rows="10" cols="30"></textarea>
  22.         </section>
  23.     <script>
  24.         function randomizeChars() {
  25.             var originalText = document.getElementById("textInput").value;
  26.             var neuerText = "";
  27.            
  28.             for (i = 0; i < originalText.length; i++) {
  29.                 if(Math.round(Math.random()) == 0) {
  30.                     if(originalText.charAt(i) == "!") { //Ausrufezeichen durch 1 ersetzten
  31.                         neuerText += "1";
  32.                     } else {
  33.                         neuerText += originalText.charAt(i).toUpperCase();
  34.                     }
  35.                    
  36.                 } else {
  37.                     neuerText += originalText.charAt(i).toLowerCase();
  38.                 }
  39.             }
  40.             document.getElementById("textOutput").innerHTML = neuerText;
  41.         }
  42.    
  43.     </script>
  44.        
  45.     </body>
  46. </html>
Add Comment
Please, Sign In to add comment