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.
Checkerboard Patterns by using JsHow to get Checkerboard Patterns like in the example??
Page 1 of 1
1 Replies - 1209 Views - Last Post: 27 July 2008 - 04:10 PM
Replies To: Checkerboard Patterns by using Js
#2
Re: Checkerboard Patterns by using Js
Posted 27 July 2008 - 04:10 PM
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:
Hope that helps.
Here is something that may helps:
<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.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|