Jump to content

JavaScript String Halp

Goldensapling
Go to solution Solved by HPWebcamAble,

Did you try a newline?

kits[0] = "THE TROLL\n" + "\n" + "> Airdrop";

If not, this might work:

kits[0] = "THE TROLL<br><br>"+"> Airdrop";

 

Yo, I'm absolute garbage at JavaScript (although I'm familiar with Java), and I'm trying to get multi-line strings to work in an array.

I'm trying to print each string on a new line, but I honestly have no clue how to in JavaScript

btw the random stuff is to cycle through a bunch of strings in the array

 

Here's my current trashy code : 

<p><script type="text/javascript" language="JavaScript">
    <!--
        var kits = new Array ();
        kits[0] =     "THE TROLL" +
                    "" +
                    "> Airdrop";
    
        
        var i = Math.floor(0*Math.random())
        document.write('<span style="font-family: arial; font-size: 32px">' + kits[i] + '</span>');
    //-->
    </script></p>

 

 

 

I'm a fucking AMD kawaii weeaboo desu I have seen the light


i5 6600k EVGA 980 FTW Z170A PC Mate 1TB WD Blue240GB SSD Plus NZXT S340 | EVGA 600b  | Dedotated 8GB

 

Link to comment
Share on other sites

Link to post
Share on other sites

Did you try a newline?

kits[0] = "THE TROLL\n" + "\n" + "> Airdrop";

If not, this might work:

kits[0] = "THE TROLL<br><br>"+"> Airdrop";

 

i7 4790k | MSI Z97S SLI Krait Edition | G.Skill Ripjaws X 16 GB | Samsung 850 EVO 500 GB | 2x Seagate Barracuda 2TB | MSI GTX 970 Twin Frozr V | Fractal Design R4 | EVGA 650W

A gaming PC for your budget: $800 - $1000 - $1500 - $1800 - $2600 - $9001

Remember to quote people if you want them to see your reply!

Link to comment
Share on other sites

Link to post
Share on other sites

You don't have to declare an array in javascript you can simply type:

 

var kits = {"THE TROLL", "", "> Airdrop"};

 

That would leave you with an array of kits(0), kits(1), kits(2).

Plus a for loop would work better to display the array:

 

var count = 0;

for (count = 0; count < 3; count++)

{

     document.write('<span style="font-family: arial; font-size: 32px">' + kits[count] + '</span>');

}

 

this should work but let me know if it doesn't

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, HPWebcamAble said:

Did you try a newline?


kits[0] = "THE TROLL\n" + "\n" + "> Airdrop";

If not, this might work:


kits[0] = "THE TROLL<br><br>"+"> Airdrop";

 

\n doens't work, but <br> did

 

Thank you based HPWebcamAble

I'm a fucking AMD kawaii weeaboo desu I have seen the light


i5 6600k EVGA 980 FTW Z170A PC Mate 1TB WD Blue240GB SSD Plus NZXT S340 | EVGA 600b  | Dedotated 8GB

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, VOLUNTEERbrowncoat said:

That would leave you with an array of kits(0), kits(1), kits(2).

Plus a for loop would work better to display the array:

 

Thank you for the declaring advice, but as for a for loop, the point is to randomize between the array, not to print the whole array

I'm a fucking AMD kawaii weeaboo desu I have seen the light


i5 6600k EVGA 980 FTW Z170A PC Mate 1TB WD Blue240GB SSD Plus NZXT S340 | EVGA 600b  | Dedotated 8GB

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Goldensapling said:

Thank you for the declaring advice, but as for a for loop, the point is to randomize between the array, not to print the whole array

I didn't know you were going for randomization, my bad.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×