Question

3. Write code that will produce the following image: (Javascript/html) (a) * ** *** **** *****...

3. Write code that will produce the following image: (Javascript/html)

(a)

*

**

***

****

*****

(b)

*

***

*****

*******

*********

(This one is supposed to be in a pyramid shape-it just doesn't show up on this website)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

<!DOCTYPE html>
<html>
<body>

<p id="stars"></p>

<script>
var result = "";
var i;
var j;
for (i = 1; i <= 5; i++) {
   for (j = 1; j <= i; j++)
       result += "*";
result += "</br>";
}
document.getElementById("stars").innerHTML = result;
</script>

</body>
</html>

<!DOCTYPE html>
<html>
<body>

<p id="stars"></p>

<script>
var result = "";
var i;
var j;
for (i = 1; i <= 5; i++) {
   for (j = 1; j <= 2*(5-i); j++)
       result += "&nbsp;";
   for (j = 1; j <= 2*i-1; j++)
       result += "*";
result += "</br>";
}

document.getElementById("stars").innerHTML = result;
</script>

</body>
</html>

Add a comment
Know the answer?
Add Answer to:
3. Write code that will produce the following image: (Javascript/html) (a) * ** *** **** *****...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT