Any javascript gurus wanna help me solve a problem

new2AMD

Diamond Member
Jul 18, 2001
5,312
0
0
I have to solve a problem for my javascript class and I am hung up on it. It should mainly deal with arrays. Im taking a night class to get some experience in programming while working and have a few questions. If you have time to help please PM me. Id appreciate it.
 

new2AMD

Diamond Member
Jul 18, 2001
5,312
0
0
This may be tough to explain but I will try.
Im confused as to wether I can take an input value (via a text box) and create an array from it. Then create an output that shows the contents of the array. The array would be the length of the user inputted number. The output would be that many rows long. each row would contain as many numbers as the row number it is. row 1 contains 1 number and so on.

make sense?
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
var count = Number(documenbt.getElementById('someid').value);
for(var i = 0; i < count; i++){
for(var j = 0; j<i; j++){
document.getElementById('someelement').innerHTML += j + ' ';
}
document.getElementById('someelement').innerHTML += '<br/>';
}
 

new2AMD

Diamond Member
Jul 18, 2001
5,312
0
0
thanks that really helps. I placed that in my function and made a couple tweaks to get it to do what I needed. The only thing I need to do now is make the corresponding numbers in the row not be sequential but actually a sum of the previous 2 numbers in the row. So

1
1 1
1 1 2
1 1 2 3