Zufallsgenerator


  • Beerdealer
  • 2060 Aufrufe 2 Antworten

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Zufallsgenerator

    Servus!

    Zu aller erst, ich bin der totale html bzw. Java Noob. :hy:

    Ich soll einen Zufallsgenerator erstellen, der aus 12 Namen zufällig einen aussucht.
    Ich hab mal im Inet gesucht, und hab mir so'n paar scriptschnipsel zusammengetragen.
    Vielleicht kann mir einer das script auf 12 "quotes" erweitern und so korrigieren, dass es auch läuft...

    <head>
    <script language="JavaScript">
    <!-- Verstecken für ältere Browser --
    var a = Math.random() + ""
    var rand1 = a.charAt(5)
    quotes = new Array
    quotes[1] = "1"
    quotes[2] = "2"
    quotes[3] = "3"
    quotes[4] = "4"
    quotes[5] = "5"
    quotes[6] = "6"
    quotes[7] = "7"
    quotes[8] = "8"
    quotes[9] = "9"
    quotes[0] = "10"
    var quote = quotes[rand1]
    <body>
    <script language="JavaScript">
    <!-- Verstecken für ältere Browser --
    document.write("<i>" + quote + "</i>")
    </body>
    </head>


    Ich will halt im Endeffekt, dass wenn ich auf die "html" datei, in der das Script verbaut ist klicke, er mir einen der Quotes rausschmeißt, und das halt zufällig, is ja logo...

    vielen Dank

    Gruß
  • Sers

    HTML-Quellcode

    1. <html>
    2. <head>
    3. <script language="JavaScript">
    4. quotes = new Array;
    5. quotes[1] = "1";
    6. quotes[2] = "2";
    7. quotes[3] = "3";
    8. quotes[4] = "4";
    9. quotes[5] = "5";
    10. quotes[6] = "6";
    11. quotes[7] = "7";
    12. quotes[8] = "8";
    13. quotes[9] = "9";
    14. quotes[10] = "10";
    15. quotes[11] = "11";
    16. quotes[12] = "12";
    17. a = 1 + (quotes.length-2) * (Math.random());
    18. a = Math.round(a);
    19. quote = quotes[a];
    20. </script>
    21. <body>
    22. <script language="JavaScript">
    23. document.write('<i>' + quote + '</i>');
    24. </script>
    25. </body>
    26. </html>
    Alles anzeigen
    [size=1][FONT="Courier New"]###############_###_####_
    #_ __ #___ _ _| |_(_)__(_)__ _ _ _###############new uploads: [1] [2] [3] [4] [5] [6] [7] [8]
    |#'##\/ _ \ '_|##_| / _| / _` | ' \
    |_|_|_\___/_|##\__|_\__|_\__,_|_||_|###############Bis 28. Sept. weg[/FONT][/size]