I need to create a table 3x3, using two loops. Inside each cell, my name has to appear. I am unsure how to do this! Please help!

Recommended Answers

All 4 Replies

Without giving away too much, you need the two loops, one for the rows and one for the columns. You need to figure out how to organise the loops so for each row you put in the correct number of columns. Try to think of it in terms of what actions you need to carry at at each step of the way - it should become apparent.

if you're wondering why I didn't just give you code, well, this sounds like an progamming homework/assignment stuff and you need to be able to figure how to create algorithms yourself or you'll never be good at this.
Having said that, if you show us a pretty good attempt that isn't quite right, I'm sure someone would help you finish it off.

Fair enough. I will get back at it again! I've spent 4 hours trying to figure this out and yes it is a homework assignment. I did very well with HTML last semester but I'm finding Javascript is a lot harder to understand. At least for me. Thanks for your help.

ok so... I'm really stumped... this is what i have so far... i've tried everything... i think i'm going to need to hire a tutor or something...

        <title>Homework Loops</title>
                <td id="cell1">Mark</td>
                <td id="cell2">Mark</td>
                <td id="cell3">Mark</td>
                <td id="cell4">Mark</td>
                <td id="cell5">Mark</td>
                <td id="cell6">Mark</td>
                <td id="cell7">Mark</td>
                <td id="cell8">Mark</td>
                <td id="cell9">Mark</td>
            var table = '';
            var rows = 3;
            var cols = 3;
            for (var r = 0; r < rows;r++)
                table += '<tr>';
            for(var c = 1;c <= cols;c++)
                table += '<td>' + c + '</td>';
                table += '</tr>';
            document.write('<table border=1>' + table + '</table>')




I GOT IT! i had to change [ table += '<td>' + c + '</td>'; ] to [table += '<td>' + 'mark' + '</td>';] its working now! Thanks for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.