Computer Science, asked by tulsikasera1631, 8 months ago

What will be the output of the following JavaScript code? for(i=1; i<=5; i++) { document.write(""
"") for(j=1; j<=i; j++) document.write(""*"") }

Answers

Answered by Divyanshi1423
0

Answer:

plz refer to the attachment and if correct than plz mark me as brainlist

Attachments:
Answered by shilpa85475
0

The output of the above mentioned java script is,

*

**

***

****

*****

EXPLANATION:  

The given code is a nested-for loop

for(i=1; i<=5; i++)

{ document.write(“<BR>”) for(j=1; j<=i; j++) document.write(“*”) }

The variable i=1 initially and loop will be executed until i<=5. Now, the second loop j starts with 1 and works until it is <=5.  

There is a line break via document.write <”BR”> after the first loop is executed. Then second loop starts. Every time second loop ends, code instructs to write * by document.write(‘*’).

Thus, the values of I and j determine the number of times * is printed five times with line breaks.

*

**

***

****

*****

Similar questions