2
Contributors
4
Replies
11
Views
1 Year
Discussion Span
Last Post by Mark_46
0

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.

0

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.

0

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...

<html>
    <head>
        <title>Homework Loops</title>
    </head>
    <body>
        <table>
            <tr>
                <td id="cell1">Mark</td>
                <td id="cell2">Mark</td>
                <td id="cell3">Mark</td>
            </tr>
            <tr>
                <td id="cell4">Mark</td>
                <td id="cell5">Mark</td>
                <td id="cell6">Mark</td>
            </tr>
            <tr>
                <td id="cell7">Mark</td>
                <td id="cell8">Mark</td>
                <td id="cell9">Mark</td>
            </tr>
        </table>
        <script>
            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>')

        </script>

    </body>

</html>
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.