[ / / / / / / / / / / / / / ] [ dir / random / 93 / biohzrd / hkacade / hkpnd / tct / utd / uy / yebalnia ][Options][ watchlist ]

/prog/ - Programming

Programming
You can now write text to your AI-generated image at https://aiproto.com It is currently free to use for Proto members.

Name
Email
Subject
REC

0:00

Comment *
File
Select/drop/paste files here
Password (Randomized for file and post deletion; you may also set your own.)
Archive
* = required field[▶Show post options & limits]
Confused? See the FAQ.
Expand all images

File (hide): 1450105938013.png (106.97 KB,1649x494,1649:494,2015-12-13-130936_1649x494….png) (h) (u)

[–]

642eb3 (10) No.3717 >>4257 >>4282 >>4527 [Watch Thread][Show All Posts]

 
var a0 = document.getElementsByTagName("audio")[0];
var a1 = document.getElementsByTagName("audio")[1];
var a2 = document.getElementsByTagName("audio")[2];
var a3 = document.getElementsByTagName("audio")[3];

How to do this in a for loop?

____________________________
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

642eb3 (10) No.3719>>4257

Go back to school.

Read a book.

Do any fucking beginner's tutorial.

If you are stumped on this, you really need to be reading, not asking questions on 8chan.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

642eb3 (10) No.3720>>4527

The answer: you can't do that in a for loop. Your question is focused too heavily. Step back and show more code, and this awfulness can be removed.

For example, if all you want to is frob all the audios on the page, i.e., if your code goes on to say frob(a0); frob(a1); etc., then you can do this:

var audio = document.getElementsByTagName("audio")
for (var i = 0, length = audio.length; i < length; i++) {
frob(audio[i])
}

Actually b/c JavaScript you totally can do exactly what you wrote with a for loop, assuming global scope on those vars, but I'm not going to tell you how, because it's fucking stupid.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

642eb3 (10) No.3746

You don't.

You keep those things in the array.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

642eb3 (10) No.3801>>4257


#def MAGIC 69

T a[MAGIC];
// magically allocated

for (auto i = 0; i < MAGIC; ++i) {
a[i] = thingy.get("tagname")[i];
// magically copied
}

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

642eb3 (10) No.4257>>4527

File (hide): 1464941590417.webm (7.83 MB,640x356,160:89,big guys song.webm) (h) (u) [play once] [loop]

>>3717 (OP)

>var OPisAFaggot = document.getElementsByTageName("audio")

>access variables by doing OPisAfaggot[X], where X = what ever the fuck one you want

>>3719

To be fair I had this problem too when I was a noobfag. I wanted to create new variables using a for loop but didn't know how the fuck to do that. Now I know you can't and must use an array.

>>3801

Anon, please. I'm 99% sure getElementsByTagName returns a populated array so you don't have to declare an empty array and assign all of the elements using a for loop. What you're using isn't even Javascript you fag.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

642eb3 (10) No.4282>>4303

File (hide): 1466136757701.png (22.02 KB,564x482,282:241,H E L L O W O R L D.png) (h) (u)

>>3717 (OP)

Hand copy this C code, compile it, then run it.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

642eb3 (10) No.4303>>4304

>>4282

Is this a virus?

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

642eb3 (10) No.4304

>>4303

Please don't compile that code. It right fucked my computer… I'm getting a new HD today.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

642eb3 (10) No.4527

>>4257

>To be fair I had this problem too when I was a noobfag. I wanted to create new variables using a for loop but didn't know how the fuck to do that. Now I know you can't and must use an array.

You're still a noob. Learn how namespaces work, idiot.

>>3717 (OP)

Sure, OP. Other fags here don't seem to know how to answer basic questions because they're actually stumped as to how to perfectly emulate your code. It's easy, actually.


for (var x = 0; x <= 3; x++) window['a' + x] = document.getElementsByTagName("audio")[x];

After that code runs, you can then reference a0, a1, a2, and a3 as normal.

You might want to consider making a namespace of their own to go into though, that way they won't just be tossed into the same group as everything else.

>>3720

Get off this board, idiot. Don't answer questions if you don't know the answer.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.



[Return][Go to top][Catalog][Screencap][Nerve Center][Random][Update] ( Scroll to new posts) ( Auto) 5
9 replies | 2 images | 1 UIDs | Page ?
[Post a Reply]
[ / / / / / / / / / / / / / ] [ dir / random / 93 / biohzrd / hkacade / hkpnd / tct / utd / uy / yebalnia ][ watchlist ]