DEV Community

Nimal Anand
Nimal Anand

Posted on

looping sums

1) expected output : displaying 5 one's vertically.

let i=1;
let count=1;
while(i<=5){
console.log(count);
i++;
}


2)expected output : displaying 5 one's horizantally.

let i=1;
let m="";
while(i<=5){
m+="1 ";
i++;
}
console.log(m)


3)expected output: displaying 12345 vertically.

let i=1;

while(i<=5){
console.log(i);
i++;
}


4) expected output: displaying 12345 horizantally.

let i=1;
let count="";
while(i<=5){
count+=i;
i++;
}
console.log(count)

if we want these to be printed vertically.

let i=1;
let count="";
while(i<=5){
count+=i+"\n";
i++;
}
console.log(count)

if we want spaces between 1 2 3 4 5.

let i=1;
let count=" ";
while(i<=5){
count+=i+" ";
i++;
}
console.log(count)


Top comments (1)

Collapse
 
gunalan22082002 profile image
Guna Ramesh

interesting!