0% found this document useful (0 votes)
10 views5 pages

Loops Assignment

The document outlines a series of JavaScript programming tasks involving loops. It includes creating and printing arrays of emails, generating multiplication tables, and printing star patterns in various shapes (right-angled triangle, left-angled triangle, and pyramid). Each task is accompanied by sample code and expected output for clarity.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Loops Assignment

The document outlines a series of JavaScript programming tasks involving loops. It includes creating and printing arrays of emails, generating multiplication tables, and printing star patterns in various shapes (right-angled triangle, left-angled triangle, and pyramid). Each task is accompanied by sample code and expected output for clarity.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LOOPS ASSIGNMENT

Task: 1. Create an array for 5 emails and print 3 emails and exit the loop if index is greater
than 2 .
Code:
<script>
Let
emails=['lucky@[Link]','akhil@[Link]','rohit@[Link]','akula@[Link]','lakshman
@[Link]'];
for (let i= 0; i <= [Link]; i++ ){
if(i>2){
break;
}
[Link](emails[i]);
}
</script>
Output:

Task: 2. Create an array for 5 emails and print all the emails using while loop/ForLoop .
Code:
<script>
let
emails=['lucky@[Link]','akhil@[Link]','rohit@[Link]','akula@[Link]','lakshman
@[Link]'];
for(let i=0;i<=[Link];i++){
[Link](emails[i]);
}
</script>
Output:

Task:[Link] a JavaScript program using a for loop to print the multiplication table of 2.
Expected Output:
2x1=2
2x2=4
2x3=6
...
2 x 10 = 20

Code:
<script>
for(i=1;i<=10;i++){
let a=(2 + ' x ' + i + ' = ' + (2*i) )
[Link](a);
}
</script>
Output:
Task:4: Printing Stars in a Right-Angled Triangle
Create a JavaScript program using a nested for loop to print a right-angled triangle of stars.
The user should input the number of rows.
Expected Output (for 5 rows):
*
**
***
****
*****
Code:
Approch-1:
<script>
for(i=1;i<=5;i++){
let a ="*";
[Link]([Link](i));
}
</script>

Approch-2:
<script>
let a="*";
[Link](a);
for(i=1;i<5;i++){
a+="*"
[Link](a);
}
</script>
Output:

Task:5: Printing Stars in a Left-Angled Triangle


Write a JavaScript program using a nested for loop to print a left-angled triangle of stars. The
user should input the number of rows.
Expected Output (for 5 rows):
*****
****
***
**
*
Code:
<script>
for(let i = 5 ; i > 0 ; i--){
let a ="*";
[Link]([Link](i));
}
</script>

Output:
Task:6: Printing Stars using for loops to print a pyramid of stars.
Expected Output (for 5 rows):
*
***
*****
*******
Code:
<script>
let n=5;
for(let i = 1 ; i <= n ; i++){
a='*'.repeat(2*i-1);
s=' '.repeat(n-i);
[Link](s+a);
}
</script>

Output:

You might also like