Let row while row 3 row

This preview shows page 3 - 7 out of 19 pages.

let row; while (row <= 3) { document.writeln("<strong>HOME</strong><br>"); row++; } document.writeln("Second One<br>"); row = 1; for (; row <= 3; ) { document.writeln("<strong>HOME</strong>"); row++; } row = 1; for (row <= 3) { document.writeln("Third One<br>"); row++; } row = 1; for (; row <= 3; row++;) { document.writeln("<strong>HOME</strong>"); }
Image of page 3
let maxRows = 3, row; for (row =1; row <= maxRows; row++) { document.writeln("display 4 asterisks<br>") } How to print asterisks based on number entered in prompt let maxRows = 5, row, col; let ast = Number (prompt("Enter number of asterisk")); for (row = 1; row <= maxRows; row++) { for (col = 1; col <= ast; col++) { document.writeln("*"); } document.writeln("<br>"); } How to make one row a $ sign and one row a *. (use the remainder. Aka use %) let maxRows = 5, row, col; let ast = Number (prompt("Enter number of asterisk")); for (row = 1; row <= maxRows; row++) { for (col = 1; col <= ast; col++) { if (row % 2 == 0) { document.writeln("*"); } else { document.writeln("$"); } } document.writeln("<br>"); } How to make one column a $ sign and one row a *. (use the remainder. Aka use %) let maxRows = 5, row, col; let ast = Number (prompt("Enter number of asterisk")); for (row = 1; row <= maxRows; row++) { for (col = 1; col <= ast; col++) { if (col % 2 == 0) { document.writeln("*"); } else { document.writeln("$"); } } document.writeln("<br>");
Image of page 4
} -outer loop is drawing row by row. Inner loop is drawing whatever you want to see in that row How to draw a triangle. Use row instead instead of ast let maxRows = Number(prompt("Enter rows")), row, col; for (row = 1; row <= maxRows; row++) { for (col = 1; col <= row; col++) { document.writeln("*"); } document.writeln("<br>"); } TRACE TABLES (for the drawing a triangle example). The outer loop says row 1, and then the inner loop is spinning its wheels. And then we move to row 2 and then the inner loop is spinning its wheels again maxRow row col 5 1 2 1 2 3 1 2 3 MARCH 27 -bootstrap: not going to be on any exam or quiz but on projects, bootstrap allows the html to adapt to different devices, can cut and paste the bootstrap examples he posted and modify them in our own documents to fit our needs -bootstrap is like a library of software that provides support. Will make html better and allow it to adapt to different environments -design and decorate pages using bootstrap “I have this while loop. Rewrite it using a for loop” → will be an exam question -the outer loop plays the role of going row by row. Inner loop plays the role of in the row, what is the particular one i want. Draw triangle where there are more asterisks in the upper rows and less in the lower rows let maxRows = Number(prompt("Enter rows")), row, col; let numSpaces = maxRows - 1; for (row = 1; row <= maxRows; row++) {
Image of page 5
/*prints spaces in rows*/ for (col = 1; col <= numSpaces; col++) { document.writeln("&nbsp;&nbsp;"); /*&nbsp; is a character reference and represents an empty space. Have two of them here due to the spacing on the screen*/ } /*print asterisks in row*/ for (col = 1; col <= row; col++) { document.writeln("*"); } numSpaces--; document.writeln("<br>"); } Draw two triangles → copy and paste code for first triangle but delete the word “let” from pasted code because code is already defined let maxRows = Number(prompt("Enter rows")), row, col; let numSpaces = maxRows - 1; for (row = 1; row <= maxRows; row++) { /*prints spaces in rows*/ for (col = 1; col <= numSpaces; col++) { document.writeln("&nbsp;&nbsp;"); /*&nbsp; is a character reference and
Image of page 6
Image of page 7

You've reached the end of your free preview.

Want to read all 19 pages?

  • Spring '13
  • Fawzi

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture