Skip to content

Commit 2498267

Browse files
added new problems solution ad, even and more odd, and sum problems has been added here
1 parent 6e25f70 commit 2498267

File tree

7 files changed

+155
-0
lines changed

7 files changed

+155
-0
lines changed

D. Loop/While/commitment.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*** Problem-1
2+
3+
"I will invest at least 6 hrs every single day for next 60 days!" this message 60 times. So display this.
4+
5+
*/
6+
// Solution-1
7+
let day = 1;
8+
while (day <= 60) {
9+
console.log("I will invest at least 6 hrs every single day for next " + day + " days!");
10+
day++;
11+
}
12+
13+
// Solution-2
14+
let i = 1;
15+
while (i <= 60) {
16+
console.log(`I will invest at least 6 hrs every single day for next ${i} days!`);
17+
i++;
18+
}

D. Loop/While/countdown.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*** Problem-7
2+
3+
Implement a countdown timer that counts down from 81 to 65.
4+
5+
*/
6+
7+
// Solution-1
8+
let j = 81;
9+
while (j >= 65) {
10+
if (j % 2 === 0 || j % 2 === 1) {
11+
console.log(j);
12+
j--;
13+
}
14+
}
15+
16+
// Solution-2
17+
let i = 81;
18+
while (i >= 65) {
19+
console.log(i);
20+
i--;
21+
}
22+

D. Loop/While/even.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*** Problem-4
2+
3+
Find all the even numbers from 78 to 98.
4+
5+
*/
6+
7+
8+
// Solution 1
9+
let i = 78;
10+
while (i <= 98) {
11+
if (i % 2 === 0) {
12+
console.log(i);
13+
}
14+
i++;
15+
}
16+
17+
// Solution 2
18+
let j = 78;
19+
while (j <= 98) {
20+
console.log(j);
21+
j += 2
22+
}

D. Loop/While/multiplication.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*** Problem-6
2+
*
3+
Generate a multiplication table for number 9
4+
5+
*/
6+
7+
// Solution - 1
8+
let i = 1;
9+
while (i <= 10) {
10+
console.log('9 * ' + i + ' = ' + (9 * i));
11+
i++;
12+
}
13+
14+
// Solution-2
15+
let j = 1;
16+
while (j <= 10) {
17+
console.log(`9 * ${j} = ${9 * j}`);
18+
j++;
19+
}

D. Loop/While/odd.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*** Problem-2
2+
3+
Find all the odd numbers from 61 to 100.
4+
5+
*/
6+
7+
// Solution-1
8+
let i = 61;
9+
while (i <= 100) {
10+
i++;
11+
if (i % 2 === 1) {
12+
console.log(i);
13+
}
14+
}
15+
16+
17+
// solution-2
18+
let j = 61;
19+
while (j <= 100) {
20+
console.log(j);
21+
j += 2;
22+
}

D. Loop/While/sum-&-even.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*** Problem-5
2+
3+
Display sum of all the even numbers from 51 to 85.
4+
*/
5+
6+
// Solution-1
7+
let i = 51;
8+
sum = 0;
9+
while (i <= 85) {
10+
if (i % 2 === 0) {
11+
sum = sum + i;
12+
}
13+
i++;
14+
}
15+
console.log(sum);
16+
17+
18+
// Solution-2
19+
let j = 52;
20+
add = 0;
21+
while (j <= 85) {
22+
add = add + j;
23+
j += 2;
24+
25+
}
26+
console.log(add);

D. Loop/While/sum-&-odd.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*** Problem-3
2+
3+
Display sum of all the odd numbers from 91 to 129.
4+
***/
5+
6+
// Solution-1
7+
let i = 91;
8+
sum = 0;
9+
while (i <= 129) {
10+
if (i % 2 === 1) {
11+
sum = sum + i;
12+
}
13+
i++;
14+
}
15+
console.log("This is total of odd number : ", sum);
16+
17+
18+
// Solution-2
19+
20+
let j = 91
21+
add = 0;
22+
while (j <= 129) {
23+
add = add + j;
24+
j += 2;
25+
}
26+
console.log("This is total of odd number : ", add);

0 commit comments

Comments
 (0)