| | |
for label and design output
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 5
Reputation:
Solved Threads: 0
ok,
i wrote a label for statement that on row 1 has "*" and nine spaces.
row 2 has 2 "*" and 8 spaces and so on...... till my tenth row has ten "8"
now i need to do the opposite;
row 1; 9 spaces and 1 *
row 2; 8 spaces and 2 * and so on......
row 10 has 10 *
here is what i have so far. the first nextRow Label is good but the second one isn't.
i wrote a label for statement that on row 1 has "*" and nine spaces.
row 2 has 2 "*" and 8 spaces and so on...... till my tenth row has ten "8"
now i need to do the opposite;
row 1; 9 spaces and 1 *
row 2; 8 spaces and 2 * and so on......
row 10 has 10 *
here is what i have so far. the first nextRow Label is good but the second one isn't.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
nextRow: // target label of continue statement for ( var row = 1; row <= 10; ++row ) { document.writeln( "<br />" ); for ( var column = 10; column >= 1; --column ) { if ( column < row ) continue nextRow; // next iteration of labeled loop document.write( "* " ); } //end for } //end for nextRow: // target label of continue statement for ( var row = 1; row <= 10; ++row ) { document.writeln( "<br />" ); for ( var column = -1; column <= -10; ++column ) { if ( column < row ) continue nextRow; // next iteration of labeled loop document.write( "* " ); } //end for } //end for
Zero-G,
It's all to do with
But you should really be thinking in terms of a generalised function to do this sort of thing, with parameters to control the detailed behaviour.
For example :
Airshow
It's all to do with
column < row always being false.But you should really be thinking in terms of a generalised function to do this sort of thing, with parameters to control the detailed behaviour.
For example :
javascript Syntax (Toggle Plain Text)
function writeAsterisks(x, y){ var i, j, n, s; for( i=0,n=x; i<(1+Math.abs(y-x)); i++, n+=(x<y)?1:-1 ) { s = []; for( j=0; j<n; j++ ) { s.push('*'); } document.writeln( s.join(' ')+ '<br />' ); delete s; } } writeAsterisks(10, 1); writeAsterisks(1, 10);
50% of the solution lies in accurately describing the problem!
•
•
Join Date: Nov 2008
Posts: 5
Reputation:
Solved Threads: 0
Unfortuanly i cannot do the code that way. I need to use for statements with labels. see assignment;
Write an script that outputs xhtml to display the following patterns separately, one below the other. Use for statements to generate the patterns. All asterisks (*) should be printed by a single statement of the form document.write ( '*' ); which causes the asterisks to print side by side. A statement of the form document.write("<br />"); can be used to move to the next line. A statement of the form document.write( " " ); can be used to display a space for the last two patterns. There should be no other output programs in the program. [Hint: The last two patterns require that each line begin with an appropriate number of blank spaces. you may need to use the xhtml <pre></pre> tags.]
*
**
***
****
*****
******
*******
********
*********
**********
**********
*********
********
*******
******
*****
****
***
**
*
**********
.*********
..********
...*******
....******
.....*****
......****
.......***
........**
.........*
.........*
........**
.......***
......****
.....*****
....******
...*******
..********
.*********
**********
I have gotten the first two patterns but the last two elude me. oH, of note about this post and the last two patterns. the right border should line up. for some reason it's not posting right.
Write an script that outputs xhtml to display the following patterns separately, one below the other. Use for statements to generate the patterns. All asterisks (*) should be printed by a single statement of the form document.write ( '*' ); which causes the asterisks to print side by side. A statement of the form document.write("<br />"); can be used to move to the next line. A statement of the form document.write( " " ); can be used to display a space for the last two patterns. There should be no other output programs in the program. [Hint: The last two patterns require that each line begin with an appropriate number of blank spaces. you may need to use the xhtml <pre></pre> tags.]
*
**
***
****
*****
******
*******
********
*********
**********
**********
*********
********
*******
******
*****
****
***
**
*
**********
.*********
..********
...*******
....******
.....*****
......****
.......***
........**
.........*
.........*
........**
.......***
......****
.....*****
....******
...*******
..********
.*********
**********
I have gotten the first two patterns but the last two elude me. oH, of note about this post and the last two patterns. the right border should line up. for some reason it's not posting right.
Aha, so that's what an assignment looks like.
Well with the greatest respect to your lecturer, it's abit out of date in the direction it steers you. In particular, these days nobody should be encouraged to use
Personally, I would regard much of the assigment as advice.
Symantically, only the first two sensences are instructions. The rest have main verbs "should" and "can" and may therefore be regarded as advisory not mandatory. In English, mandation is expressed by use of the imperitive tense (as in sentences 1 and 2), or main verbs "must" or "shall".
That said, I don't think there's anything in my code which departs from the assigment - even including the advisory stuff. Here's my statement of compliance (it's a useful exercise) :
So if they argue, tell them Airshow said so.
Airshow
Well with the greatest respect to your lecturer, it's abit out of date in the direction it steers you. In particular, these days nobody should be encouraged to use
document.write(); , which is one of the greatest evils ever include in Javascript. I used it for many years before I saw the light.Personally, I would regard much of the assigment as advice.
Symantically, only the first two sensences are instructions. The rest have main verbs "should" and "can" and may therefore be regarded as advisory not mandatory. In English, mandation is expressed by use of the imperitive tense (as in sentences 1 and 2), or main verbs "must" or "shall".
That said, I don't think there's anything in my code which departs from the assigment - even including the advisory stuff. Here's my statement of compliance (it's a useful exercise) :
- Write an script that outputs xhtml to display the following patterns separately
Compliant - one below the other.
Compliant - Use for statements to generate the patterns.
Compliant - All asterisks (*) should be printed by a single statement of the form document.write ( '*' ); which causes the asterisks to print side by side.
(Advisory) Compliant - A statement of the form document.write("<br />"); can be used to move to the next line.
(Advisory) Compliant - A statement of the form document.write( " " ); can be used to display a space for the last two patterns.
(Advisory) Compliant - There should be no other output programs in the program.
(Advisory) Compliant - [Hint: The last two patterns require that each line begin with an appropriate number of blank spaces. you may need to use the xhtml <pre></pre> tags.]
(Advisory) Compliant
So if they argue, tell them Airshow said so.
Airshow
50% of the solution lies in accurately describing the problem!
Zero-G,
I guess you will want to do it your way but this will give you a clue:
Use of
Airshow
I guess you will want to do it your way but this will give you a clue:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function writeAsterisks(x, y, pad){ var i, j, n, s; document.writeln( '<pre>' ); for( i=0,n=x; i<(1+Math.abs(y-x)); i++, n+=(x<y)?1:-1 ) { s = []; if(pad){ for(j=0; j<1+Math.abs(y-x)-n; j++){ s.push(' '); } } for( j=0; j<n; j++ ) { s.push('*'); } document.writeln( s.join(' ') ); delete s; } document.writeln( '</pre>' ); } writeAsterisks(1, 10, false); writeAsterisks(10, 1, false); writeAsterisks(10, 1, true); writeAsterisks(1, 10, true);
<pre>...</pre> is good advice.Airshow
50% of the solution lies in accurately describing the problem!
•
•
Join Date: Nov 2008
Posts: 5
Reputation:
Solved Threads: 0
Airshow,
thanks forthe advice. I guess i was just interping the directions defferntly. Thanks for showing me the error in my ways...hahahaha
I like your code but it looks very complicated to me. I am going to try and work it my way, but even with your "suggestions" i'm still not seeing it. I know the <pre> tag is the key but when ever i put the tag in the code the *'s align vertically only.
i have been working on this for days with little progress. But again i appericate the advice. if you have more "prompts" feel free to give them.
thx
zero
thanks forthe advice. I guess i was just interping the directions defferntly. Thanks for showing me the error in my ways...hahahaha
I like your code but it looks very complicated to me. I am going to try and work it my way, but even with your "suggestions" i'm still not seeing it. I know the <pre> tag is the key but when ever i put the tag in the code the *'s align vertically only.
i have been working on this for days with little progress. But again i appericate the advice. if you have more "prompts" feel free to give them.
thx
zero
Zero-G,
I'm glad you appreciate my essay on bad assignment wording. Truth is there's a bit of a rebel in me still.
The second set of *** is actually easier than the first.
Every row has 10 entries. Each entry is either " " or "* ". So, doing it your way, the inner (column) loop always goes round 10 times - no need for a break.
Within the loop, all you have to do is decide each time whether to print out " " or "* ", which depends on the outer (row) loop counter. The rule is only slightly different for increasing versus decreasing.
Make sure everything is wrapped in <pre></pre> otherwise the browser will render consecutive spaces as a single space, and (in all probability) it will use a propertional font such that spaces and asterisks are different widths. You will only ever get that nice straight right edge with a "mono-spaced" font, as per <pre>.
I am determined you're going to get this right and get a good mark.
Airshow
I'm glad you appreciate my essay on bad assignment wording. Truth is there's a bit of a rebel in me still.
The second set of *** is actually easier than the first.
Every row has 10 entries. Each entry is either " " or "* ". So, doing it your way, the inner (column) loop always goes round 10 times - no need for a break.
Within the loop, all you have to do is decide each time whether to print out " " or "* ", which depends on the outer (row) loop counter. The rule is only slightly different for increasing versus decreasing.
Make sure everything is wrapped in <pre></pre> otherwise the browser will render consecutive spaces as a single space, and (in all probability) it will use a propertional font such that spaces and asterisks are different widths. You will only ever get that nice straight right edge with a "mono-spaced" font, as per <pre>.
I am determined you're going to get this right and get a good mark.
Airshow
Last edited by Airshow; Aug 29th, 2009 at 10:55 pm.
50% of the solution lies in accurately describing the problem!
•
•
Join Date: Nov 2008
Posts: 5
Reputation:
Solved Threads: 0
when i wrap everything with the pre tags it doesn't show anything, not even the patterns i had already. I know the decreassing the row pring is the "--column". this is my complete code, obviously the last label is the one i'm working on.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<?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"> <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title>Using the continue Statement with a Label</title> <script type = "text/javascript"> <!-- nextRow: // target label of continue statement for ( var row = 1; row <= 10; ++row ) { document.writeln( "<br />" ); for ( var column = 1; column <= 10; ++column ) { if ( column > row ) continue nextRow; // next iteration of labeled loop document.write( "*" ); } //end for } //end for document.writeln( "<br />" ); nextRow2: // target label of continue statement for ( var row = 1; row <= 10; ++row ) { document.writeln( "<br />" ); for ( var column = 10; column >= 1; --column ) { if ( column < row ) continue nextRow2; // next iteration of labeled loop document.write( "*" ); } //end for } //end for document.writeln( "<br />" ); nextRow3: // target label of continue statement for ( var row = 1; row <= 10; ++row ) { document.writeln( "<br />" ); for ( var column = -10; column <= 1; ++column ) { if ( column > row ) continue nextRow3; // next iteration of labeled loop document.write( "*" ); } //end for } //end for // --> </script> </head><body></body> </html>
![]() |
Similar Threads
- C# for Loop Help (C#)
- c++ cashier (C++)
- CALENDAR in TASM!!(pls check my code!!:) (Assembly)
- Help Me Plz!! (C++)
- Setting Form Controls Dynamically... (C#)
- Trouble removing My Way Search Assistant (Viruses, Spyware and other Nasties)
- CMS - Content Management Systems - Revisited... (Existing Scripts)
- PLS help me do this program.. (C++)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Change <div> text color & font without refreshing page
- Next Thread: Ajax - Fetching Records from DB
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column cookies createrange() css cursor dependent disablefirebug dom download dropdown editor element engine error events explorer ext file form forms google gwt gxt hiddenvalue highlightedword html htmlform ie8 iframe image() images internet java javascript jawascriptruntimeerror jquery jsf jsfile jump libcurl math media microsoft mimic object onerror onmouseoutdivproblem onreadystatechange parent pdf php player post problem progressbar rated rating regex runtime scroll search security select session shopping size software sql star stars synchronous text textarea unicode validation w3c web website window windowofwords windowsxp wysiwyg xml \n





