2017-03-20 6 views
0

HTMLversuchen, Buchstaben, Zahlen zusammenzustellen und Symbole in eine rotierende Zeichenfolge

so, ich versuche, eine sich wiederholende console.log zu haben, der die Ziffern ändert jede mögliche Kombination in einer beliebigen Anzahl von Ziffern zu zeigen. Ich habe eine Reihe von Variablen erstellt, die die Ziffern definieren, die ich verwenden möchte, und habe versucht, eine Funktion zu erstellen, die Buchstabenarrays "console.log (s [0])" verwendet, um jedes Zeichen in der Zeichenfolge zu verwenden. Aber wenn ich versuche, den Code auszuführen, protokolliert er einmal b an der Konsole und stoppt. Der Code:

  function start() 
      { 
       var inputDigit = document.getElementById("inputDigit").value; 
       var lowerCaseAlpabet = "abcdefghijklmnopqrstuvwxyz"; 
       var upperCaseAlpabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
       var symbols = "*&^%$#@!()<>?/.,|}{][-_=+~`" 
       var Numbers = "1234567890" 
       var all = lowerCaseAlpabet+upperCaseAlpabet+symbols+Numbers 
       console.log(all) 
       var allLength = all.length - 1 


       var digit = 0 
       digit1(all,allLength,digit) 
       function digit1(all,allLength,zero){ 

        if (digit < allLength) { 
          var finalValue = all[digit] 
          var digit = digit + 1 
          return finalValue 
         } 
        return finalValue 
        var digit = digit + 1 
        console.log(finalValue) 
        digit1(all,allLength,digit) 
       } 



      } 

Der gesamte Code Dokument:

<!DOCTYPE html> 
 
\t \t \t \t <html> 
 
\t \t \t \t <head> 
 
\t \t \t \t <!--<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>--> 
 
\t \t \t \t <title>Passcode Compiler</title> 
 
\t \t \t \t <h1>Welcome to the Passcode Compiler</h1> 
 
\t \t \t \t <h2>Please fill in the blank below with the amount of digits that you need</h2> 
 

 
\t \t \t \t </head> 
 
\t \t \t \t <body> 
 
\t \t \t \t <script> 
 

 
\t \t \t \t </script> 
 
\t \t \t \t <br> <input type="text" id="inputDigit">compiling length</input><br><!--This takes the year input--> 
 
\t \t \t \t <button onclick="start()">Submit</button><br><!--This submits the input values above to the javascript code below--> 
 
\t \t \t \t <script> 
 

 

 
\t \t \t \t function start() 
 
\t \t \t \t { 
 
\t \t \t \t var inputDigit = document.getElementById("inputDigit").value; 
 
\t \t \t \t var lowerCaseAlpabet = "abcdefghijklmnopqrstuvwxyz"; 
 
\t \t \t \t var upperCaseAlpabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
 
\t \t \t \t var symbols = "*&^%$#@!()<>?/.,|}{][-_=+~`" 
 
\t \t \t \t var Numbers = "1234567890" 
 
\t \t \t \t var all = lowerCaseAlpabet+upperCaseAlpabet+symbols+Numbers 
 
\t \t \t \t console.log(all) 
 
\t \t \t \t var allLength = all.length - 1 
 

 

 
\t \t \t \t var digit = 0 
 
\t \t \t \t digit1(all,allLength,digit) 
 
\t \t \t \t function digit1(all,allLength,zero){ 
 

 
\t \t \t \t if (digit < allLength) { 
 
\t \t \t \t var finalValue = all[digit] 
 
\t \t \t \t var digit = digit + 1 
 
\t \t \t \t return finalValue 
 
\t \t \t \t } 
 
\t \t \t \t return finalValue 
 
\t \t \t \t var digit = digit + 1 
 
\t \t \t \t console.log(finalValue) 
 
\t \t \t \t digit1(all,allLength,digit) 
 
\t \t \t \t } 
 

 

 

 
\t \t \t \t } 
 

 
\t \t \t \t </script> 
 
\t \t \t \t <h4> 
 

 
\t \t \t \t </h4> \t 
 
\t \t \t \t </body> 
 
\t \t \t \t </html> 
 
\t \t \t \t </!doctype> 
 
\t \t \t \t <!--setTimeout(function(){/*YourCode*/},1000);
Alle Ideen, wie dieses Problem beheben? Denken Sie daran, ich habe die Eingabe nicht wichtig gemacht, so sollte es unabhängig von der Eingabe funktionieren.

Antwort

0

Der Code nach einer Rückkehr nicht ausführen:

return finalValue 
var digit = digit + 1 
console.log(finalValue) 
digit1(all,allLength,digit) 

In diesem Code-Schnipsel, keine der Linien nach der Rückkehr wird ausgeführt, da eine Funktion beendet, wenn es eine return-Anweisung trifft.

Wenn Sie die Zahl erhöhen möchten, die außerhalb Ihrer Funktion definiert ist, können Sie sie nicht erneut als var darin deklarieren. Also, werden Sie Ihre Linie ändern

var digit = digit + 1;

zu

digit++;

Also habe ich mit der Anpassung der Code beginnen würde, diese zu berücksichtigen.

Verwandte Themen