Friday, January 10, 2014

Interesting Interview

During an interview, the interviewee drew an image of a checker board on the white board and asked me to code it on the white board.  So I began to code it using javascript and built a string var containing the table markup to represent a checker board.  When I was finished, he looked at it and asked me some questions regarding it.  So I began to defend my code...
Two days later, I decided to actually build out the checker board from the interview and saw where I could improve upon my original code.  This time I used HTML5 and JQuery. Here is a snipit of the code I came up with to display a checker board;

<script src="js/jquery-1.10.2.js"></script>
        <script type="text/javascript">
            $(document).ready(function (){
                var iRow = 8;
                var iCol = 8;
                
                var sHtml = "<table id='tblCB' style='margin:0 auto; border-collapse:collapse;box-shadow: 1px 1px 1px #999;'>";
                
                //generate rows
                for(var i = 0; i < iRow; i++){
                    sHtml += "<tr>";
                                        
                    //generate columns
                    for(var x = 0; x < iCol; x++){
                        if((i%2 == 0 && x%2 != 0) || (i%2 != 0 && x%2 == 0)){
                            sHtml += "<td class='dark' style='margin:0;border:1px solid #000;'>&nbsp;</td>";
                        }else{
                            sHtml += "<td style='margin:0;border:1px solid #000;'>&nbsp;</td>";
                                    
                        }
                    }
                    sHtml += "</tr>";
                }
                sHtml += "</table>";
                
                $("#board").html(sHtml);
            });
        </script>

I would like some feedback on this, and would welcome alternatives just so I can see how others think logically.

2 comments:

Thesis writing service said...

Nice... Like it

Unknown said...

These competitions includes lot many competitions that are held on regular basis or periodically and also to succeed them you require to rack up greatest facebook suches as on your ID. buy usa likes