Hi there, this HW is for javascript. I have no idea on how to begin on how this
ID: 3665811 • Letter: H
Question
Hi there, this HW is for javascript. I have no idea on how to begin on how this is done.
Bb mod 08- 201620 Scripting. x+ https://learn valenciacollege.edu/vebapps/blackboard/content/listContent.jsp?course-id--112609-1&content;_id:7505839-1 C Search 1. The first 2 points Work out any way at all to display the following (m thinking you're going to need pre/pre tags.) 2. The next 2 points Create the above "histogram" using doc.write statements that write ONLY o a single space o a single * mark, o a single mark, or o a single line break character e line break character: 3. 2 more points Minimize the number of doc.write statements by using loops and/or other control devices 4. And the final 2 points Ask a visitor for any number from 1 through 15. The answer will be the number of lines above theline (and of course, the number below it too.) For example, the figure above would result if the visitor entered a "5 An answer of "2" would render this gram: * and a "1" would give us this:--* ew Dont allow your visitor to reply with an incorrect number or a non-numeric answer I'm NOT looking for four different solutions. After you've figured out how to do #1, tear it all down and solve #2 (or better, save a copy, in case you mess up). #1, 2, and 3 are just steps along the way Some students will skip over 1, 2, and 3, and just begin writing 4. That's OK, as long as #4 incorporates the work from the other three Some will want to work their way up to it. Most will work 2 and 3 at the same time. Some will get 1, 2, and 3, and then quit or run out of time Any way you do it, I'm only looking for ONE solution from each student. If you turn in more than ONE HTML file, I will pick one at random and grade it. You may be dismayed to see the result. (You can turn in as many CSS and js files as you think are required 12:41 PM 2/6/2016Explanation / Answer
See code below:
----------------------------------------------------
<script type="text/javascript">
n=20; //no. of rows and columns in square
space_count=0; //no. of spaced to be printed in a line
asterix_count=n; //no. of asterix to be printed in a line
//outer loop counts lines
for(i=1;i<n;i++)
{
string_to_print=""; //string to be printed per line
//inner loop prepares string to be printed.
for(j=1;j<=n;j++)
{
string_to_print+="*"; //concatenates asterics to the string
}
//prepares string of spaces to be inserted in string to be printed
space_start=parseInt(asterix_count/2);
space_end=space_start+space_count;
space_str="";
for(k=space_start;k<space_end;k++)
{
space_str=space_str+" "+" ";
}
if(space_count>0)
{
initial_part=string_to_print.substring(0, space_start);
last_part=string_to_print.substring(space_end, string_to_print.length);
string_to_print=initial_part+space_str+last_part;
}
//prints string
document.write(string_to_print+"<br>");
if(i==(n/2))
{
document.write("*");
for(j=1;j<=(n+i-3);j++)
{
document.write("-");
}
document.write("*<br>");
}
if(i>=(n/2))
{
space_count=space_count-2;
asterix_count=asterix_count+2;
}
else
{
space_count=space_count+2;
asterix_count=asterix_count-2;
}
}
</script>
------------------------------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.