vendredi 6 mars 2020

multiline random text using js

I'm trying to make a random text generator that makes more than one line but it always goes on the same line on the HTML page (I have tried \n already and it doesn't work).

I tested it on chrome, but can I get some help please if its possible to even do.

Here the code I used:

function rtg(maxChar, maxLines) {
var ranChar = "";
var count;
var alphabet = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,r,s,t,u,v,w,x,y,z,1,2,3,4,56,7,8,9,0".split(",");

for (var i = 0; i < maxLines; i++) {
     var rand = null;
     for (var x = 0; x < maxChar; x++) {
         count++;
         rand = Math.floor(Math.random() * alphabet.length);
         ranChar += alphabet[rand];
         if (maxChar == count) {
             ranChar += '\n'
             count = 0;
         }
     }
 }



Aucun commentaire:

Enregistrer un commentaire