Skip to content

Commit fbebfec

Browse files
new problems has been solved by me
1 parent a7638e3 commit fbebfec

File tree

6 files changed

+147
-0
lines changed

6 files changed

+147
-0
lines changed

E. Object/all.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* Problem-19
2+
3+
You have an object, which contains an array called students.
4+
We need to check the students array using a for loop.
5+
If "Alice" is present, it will print "Alice is in the class".
6+
If not, it will print "Alice is not in the class".
7+
8+
const classroom = {
9+
className: "JavaScript Basics",
10+
students: ["John", "Jane", "Alice", "Bob", "Eve"]
11+
};
12+
13+
*/
14+
15+
const classroom = {
16+
className: "JavaScript Basics",
17+
students: ["John", "Jane", "Alice", "Bob", "Eve"]
18+
};
19+
let alice = false;
20+
21+
for (let i = 0; i < classroom.students.length; i++) {
22+
if (classroom.students[i] === "Alice") {
23+
alice = true;
24+
break;
25+
}
26+
27+
}
28+
29+
if (alice) {
30+
console.log("Alice is in the class");
31+
}
32+
else {
33+
console.log("Alice is not in the class");
34+
}

E. Object/even-number.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Problem-17
2+
3+
Print only even numbers from the array below.
4+
const numbers = [10, 25, 30, 47, 52, 61, 70, 85, 90];
5+
6+
*/
7+
const numbers = [10, 25, 30, 47, 52, 61, 70, 85, 90];
8+
9+
10+
// Solution-1 by for loop
11+
12+
for (let i = 0; i < numbers.length; i++) {
13+
if (i % 2 === 0) {
14+
console.log(numbers[i]);
15+
}
16+
}
17+
18+
// solution-2 by while loop
19+
let j = 0;
20+
while (j < numbers.length) {
21+
j++;
22+
if (j % 2 === 0) {
23+
console.log(numbers[j]);
24+
}
25+
}

E. Object/key-vlue.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* Problem-18
2+
3+
You have a Student object. You print the key and value of the object.
4+
const student = {
5+
name: "Alice",
6+
age: 20,
7+
grade: "A",
8+
city: "New York",
9+
isGraduated: false
10+
};
11+
12+
13+
*/
14+
const student = {
15+
name: "Alice",
16+
age: 20,
17+
grade: "A",
18+
city: "New York",
19+
isGraduated: false
20+
};
21+
22+
let keys = Object.values(student);
23+
console.log(keys);
24+
for (let key in student) {
25+
console.log(`${key} : ${student[key]}`);
26+
27+
}
28+
if (student.isGraduated) {
29+
console.log("Graduated");
30+
}
31+
else {
32+
console.log("Not Graduated");
33+
}

E. Object/max-number.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Problem-15
2+
3+
Find the largest number among the following numbers using loop.
4+
const numbers = [12, 45, 78, 23, 89, 56, 99, 34];
5+
6+
*/
7+
8+
const numbers = [12, 45, 78, 23, 89, 56, 99, 34];
9+
10+
// Solution-1 by for loop
11+
let maxNumber = numbers[0];
12+
for (let i = 0; i < numbers.length; i++) {
13+
if (numbers[i] > maxNumber) {
14+
maxNumber = numbers[i];
15+
}
16+
}
17+
console.log(maxNumber);
18+
19+
20+
// solution-2 by Math.max
21+
let maxNum = Math.max(...numbers);
22+
console.log(maxNum);

E. Object/min-number.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Problem-14
2+
3+
Find the largest number among the following numbers using loop.
4+
const numbers = [12, 45, 78, 23, 100, 89, 56, 99, 34];
5+
6+
*/
7+
8+
const numbers = [12, 45, 78, 23, 100, 5, 89, 56, 99, 34];
9+
10+
// Solution-1 by for loop
11+
12+
let minNumber = numbers[0];
13+
for (let i = 0; i < numbers.length; i++) {
14+
if (numbers[i] < minNumber) {
15+
minNumber = numbers[i];
16+
}
17+
}
18+
console.log(minNumber);
19+
20+
21+
// solution-2 by Math.min
22+
let minNum = Math.min(...numbers);
23+
console.log(minNum);

E. Object/reverse-word.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* Problem-14
2+
3+
You have a string, “hello”! Write a program to reverse it and see what output it produces. */
4+
5+
let words = "hello";
6+
let revWord = " ";
7+
for (let word of words) {
8+
revWord = word + words;
9+
}
10+
console.log(`"${revWord}"`);

0 commit comments

Comments
 (0)