Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am learning javascript and at the

Status
Not open for further replies.

newtek1

Technical User
Mar 11, 2002
22
AU
I am learning javascript and at the very start of a course. I have tried to work out how to make a diamond of *s
but never get what i want.
*
***
*****
*******
*********
*******
*****
***
*
I am using 9 rows and 9 columns. I have visualised a grid with the *diamond inside but where do I start?

Var=linenum,
cols;
For (linenum=5 && cols=1)
document.writeln(*)
Can anyone point me to some more information that I may be able to understand please?
 
hey newtek1 welcome to Javascript.

You can probably find as many different ways to do this as there are people in this forum.

I would imagine a fairly easy way would be to create a 9x9 table and fill in X's where you want them that could be done with javascript using the 'writeln' function. I would read up on that if I were you.

Of course you could also assign each cell an ID and then use innerHTML to turn on X's in the necessary cells. It just depends on what you want to learn.

have fun with it.


Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
Ohhh now you got me started.

You could also use one table cell and center everything. Then put a * and then a <br> and then 3 *'s and then break... and so on.

OK I quit. I'm sure there are more ways but you'll have to come up with your own.


Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
this is for a pyramid:
aterik=&quot;&quot;
for(i=0;i<10;i++)
{
asterik+=&quot;*&quot;
document.write(&quot;<center>&quot;asterik+&quot;</center><BR>&quot;)
}

Known is handfull, Unknown is worldfull
 
oops:
document.write(&quot;<center>&quot;asterik+&quot;</center><BR>&quot;)
must be:
document.write(&quot;<center>&quot;+asterik+&quot;</center><BR>&quot;)



Known is handfull, Unknown is worldfull
 
Thanks for the quick responses , I tried the asterik script and it didn't work for me but
I have been researching and have so far got a quarter of a diamond, all i need to know is how to reverse the following script...please?



<script type =&quot;text/javascript&quot;>

nextRow:
for (var row =1; row <=5; ++row) {
document.writeln ( &quot;<br /> &quot; ) ;

for (var column = 1; column<=10; ++column) {

if (column > row)
continue nextRow;


document.write ( &quot;*&quot;);
}
}
</script>



 
here,

you had the idea...

Code:
document.writeln ('<center>')
for (var row =9; row >=1; row=row-2) {
        document.writeln ( &quot;<br/>&quot; ) ;      
        for (var column = 1; column<=10; column++ )       
        if (column > row)         
        document.write ( &quot;*&quot;);
    }
}
        for (var row =1; row <=9; row=row+2) {
        document.writeln ( &quot;<br/>&quot; ) ; 
        for (var column = 1; column<=10; column++ ) {
        if (column > row)   
        document.write ( &quot;*&quot;);
    }
}

document.writeln('</center>')
</script>


Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
thankyou, i am very grateful for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top