Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Cisco Rendon
PLUS
Cisco Rendon
Courses Plus Student 35,809 Points

I am trying to create a name table using javascript. I created the rudimentary table but having a hard time

I am trying to create a table with names only, a dynamic table. I can create it in standard html and style it with css but that will take a long time especially when you have a lot of names. We may have covered it in a js class but I cannot remember if we did or didn't. Has anyone come across something like this before? This is my code for the basic table layout, it's plain / vanilla js.

var table = '';
var rows = 2;
var cols = 4;
for (var r = 0; r < rows; r++) {
    table += '<tr>';
    for (var c = 0; c < cols; c++) {
        table += '<td>' + c + '</td>';
    }
    table += '</tr>';
}
document.write('<table>' + table + '</table>');

1 Answer

Steven Parker
Steven Parker
216,810 Points

This code will effectively create a table with multiple rows and columns.

So what exactly are you having a hard time with?

Cisco Rendon
Cisco Rendon
Courses Plus Student 35,809 Points

Steven Parker i am trying to add the names thru a set of variables as well. Just names, not an age column, nothing to technical yet just names. That is where I am hitting the way. Only way i was thinking of was creating an array of names and inserting that into the variables but it wasn't working for me.

Steven Parker
Steven Parker
216,810 Points

That sounds like a good idea, but where are the names? I don't see any in this code.