/    Sign up×
Community /Pin to ProfileBookmark

Javascript asterisk triangles

(a)
*
**


***

****

*****

******

*******

********

*********

**********

(b)


**********

*********

********

*******

******

*****

****

***

**
*

(c)
**********
*********
********
*******
******
*****
****
***
**
*

(d)
*
**


***

****

*****

******

*******

********

*********

**********

The problem is that I have tried quite a number of ways, and I can only do the first 2. The last two are actually inverted. I can’t seem to get it to display what they look like(on this post).. What am I doing wrong? Thnx for your time.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@prayeauthorSep 26.2006 — for ( var row = 1; row <= 10; ++row )

{

document.writeln( "<br />" );

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

document.write( "* " );

}
}



"</br>"

document.writeln("<br>(b)");

for ( var row = 1; row <= 10; ++row )
{
document.writeln( "<br />" );

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

if ( column > row )
{

document.write( "* " );
}
}
}

</script>


</body>

</html>

</script>
Copy linkTweet thisAlerts:
@A1ien51Sep 26.2006 — And what is your code?

all it is two nested for loops
<i>
</i>for(var i....something......){
for(var j....something.....j&lt;i.....something){
document.write("*");
}
}

fill in the blanks to finish your homework....hehhehe

Eric
Copy linkTweet thisAlerts:
@UltimaterSep 26.2006 — Make sure to use [b]&nbsp;[/b]'s (no break spaces) for the blank spaces otherwise they will be ignored.
Copy linkTweet thisAlerts:
@jvanamaliSep 26.2006 — try this

for ( var row = 1; row <= 10; ++row )

{

document.writeln( "<br />" );

for ( var column = 1; column <= row; ++column )

{

document.write( "* " );

}

}


"</br>"

document.writeln("<br>(b)");

for ( var row = 1; row <= 10; ++row )

{

document.writeln( "<br />" );

for ( var column = 1; column <= 11; ++column )

{

if ( column > row )

{

document.write( "* " );

}

}

}

"</br>"

document.writeln("<br>(c)");

for ( var row = 1; row <= 10; ++row )

{

document.writeln( "<br />" );

for ( var column = 11-row; column < 10; ++column )

{

document.write( "&nbsp;&nbsp;&nbsp;" );

}

for ( var column = 1; column <= 11-row; ++column )

{

document.write( "*
" );

}

}

"</br>"

document.writeln("<br>(d)");

for ( var row = 1; row <= 10; ++row )

{

document.writeln( "<br />" );

for ( var column = 1; column < 11-row; ++column )

{

document.write( "&nbsp;&nbsp;&nbsp;" );

}

for ( var column = 11-row; column <= 10; ++column )

{

document.write( "* " );

}

}
Copy linkTweet thisAlerts:
@prayeauthorSep 26.2006 — Works like a charm!!!
×

Success!

Help @praye spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...