Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVASCRIPT: Write a program that draws (onto the page) a square, using only asterisks. While fancy graphics are possible, simple character-based graphics can be fun

JAVASCRIPT: Write a program that draws (onto the page) a square, using only asterisks.

While fancy graphics are possible, simple character-based graphics can be fun (and are a longstanding CS tradition). Write a program that draws (onto the page) a square, using only asterisks.

Ask the user to enter a square size between 3 and 30. Keep pestering the user until they enter a number in that range. You don't need to deal with non-numeric input; assume the user will type a number.

Draw a square of the specified size. For example, if a size of 5 is requested, you'd draw this:

***** ***** ***** ***** *****

Basic implementation:

Use one loop for the top line, one loop for all middle rows (this might use nesting, or not), and, depending on your implementation, potentially one loop for the bottom line.

Challenge implementation:

Instead of a square filled in with asterisks, make it "hollow" like the one shown below. But remember that there is no such thing as "empty;" they are spaces between the asterisks in the middle rows. Also remember that HTML discards extra white space. To make the output work, try putting writing the entire square within a "preformatted" HTML block, starting with

 and ending with 
. You can put those just outside the