Welcome to Dream.In.Code
Getting Help is Easy!

Join 107,664 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,075 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Checkerboard Patterns by using Js

 
Reply to this topicStart new topic

Checkerboard Patterns by using Js, How to get Checkerboard Patterns like in the example??

AsOman
post 27 Jul, 2008 - 02:37 PM
Post #1


New D.I.C Head

*
Joined: 20 Jul, 2008
Posts: 1

Hi every body,
My question is :
I've to create a checkerboard type pattern out of asterix. So I've a line of 8 asterix ("* ") and a space between them (" "). Then it goes to the next row which is indented to make the checkboard effect.
I want the result to be like this:
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
by using while structure and only three statements which are:
document.write( "* ");


document.write( " " );

document.writeln();
In fact I get inly one row so what can I add to get the other rows???

Here is my code:
[code]
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- Fig. 7.14: increment.html -->
<!-- Preincrementing and Postincrementing. -->
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Preincrementing and Postincrementing</title>
<script type = "text/javascript">
<!--
var row = 0;
cols = 0;

while(row <= 7 )

{

document.write( "* ");


document.write( " " );

document.writeln();
row++;

}


// -->
</script>
</head><body></body>
</html>
[code]
Thank you alot.
User is offlineProfile CardPM

Go to the top of the page


BetaWar
post 27 Jul, 2008 - 04:10 PM
Post #2


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,120



Thanked 38 times

Dream Kudos: 725
My Contributions


You either have to do embeded loops or multiply columns needed by rows needed and then do an if statement to output a line break after every 8 times through the loop.

Here is something that may helps:

CODE
<script type = "text/javascript">
<!--
var row = 0;
var cols = 0;

while(row <= 7 ){
  while(cols <= 7){
    document.write( "* ");
    cols++;
  }
  document.write("<br>");
  cols = 0;
  row++;
}
// -->
</script>


Hope that helps.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/29/08 10:42PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month