Skip to content

Commit ebb02c0

Browse files
added few solved by loop
1 parent 2a4978e commit ebb02c0

File tree

7 files changed

+134
-5
lines changed

7 files changed

+134
-5
lines changed

D. Loop/Array-loop/single-string.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Output: 'TomTimTinTik'
1010
let names = ['Tom', 'Tim', 'Tin', 'Tik'];
1111

1212
// Solution-1
13-
let newArray = '';
13+
let newString = '';
1414
for (let name of names) {
15-
newArray += name
15+
newString += name
1616
}
17-
console.log(newArray);
17+
console.log(`"${newString}"`);
1818

1919

2020
// Solution-2 (Short)
2121
let addAllName = names.join('');
22-
console.log(addAllName);
22+
console.log(`'${addAllName}'`);

D. Loop/Array-loop/split-reverse-join.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Output: "I am a hard working person"
88
*/
99
const statement = "I am a hard working person";
1010
let reverseStatement = statement.split(" ").reverse().join(" ");
11-
console.log(reverseStatement);
11+
console.log(`"${reverseStatement}"`);

E. Object/access-object-property.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* Problem-3
2+
3+
Display the physics marks as output.
4+
5+
const student = {
6+
name: "Hamim Sakep",
7+
id: 5421,
8+
physics: {
9+
subject: "HSC Physics",
10+
author: "Shahjahan Tapan",
11+
marks: 30
12+
}
13+
};
14+
*/
15+
16+
const student = {
17+
name: "Hamim Sakep",
18+
id: 5421,
19+
physics: {
20+
subject: "HSC Physics",
21+
author: "Shahjahan Tapan",
22+
marks: 30
23+
}
24+
};
25+
26+
// Solution-1 by dot notation
27+
let physicsMarks = student.physics.marks;
28+
console.log(physicsMarks);
29+
30+
// Solution-2 by bracket notation
31+
let physicsMark = student["physics"]["marks"];
32+
console.log(physicsMark);

E. Object/add-property.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Problem-2
2+
3+
For this object below add a property named passenger capacity with value 5
4+
5+
const car = {
6+
make: "Toyota",
7+
model: "Corolla",
8+
year: 2020 };
9+
*/
10+
11+
const car = {
12+
make: "Toyota",
13+
model: "Corolla",
14+
year: 2020
15+
};
16+
17+
// Solution-1 by bracket notation
18+
car["passenger capacity"] = 5;
19+
console.log(car);
20+
21+
22+
23+
// Solution-2 by object method
24+
Object.assign(car, { "passenger capacity ": 5 });
25+
console.log(car);

E. Object/count-property.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Problem-3
2+
3+
Count the number of properties.
4+
5+
let student = {
6+
name: 'Ariana Grande',
7+
age: 21,
8+
city: 'Gaibandha',
9+
isStudent: true
10+
};
11+
*/
12+
13+
let student = {
14+
name: 'Ariana Grande',
15+
age: 21,
16+
city: 'Gaibandha',
17+
isStudent: true
18+
};
19+
20+
let count = Object.keys(student);
21+
console.log(count.length);

E. Object/object-&-loop.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Problem-4
2+
3+
Loop through an object and print the key - value pairs with their types
4+
5+
Input:
6+
7+
8+
let myObject = {
9+
name: 'John Doe',
10+
age: 25,
11+
city: 'Example City',
12+
isStudent: true
13+
};
14+
15+
Output:
16+
key: name | type: string
17+
key: age | type: number
18+
key: city | type: string
19+
key: isStudent | type: boolean
20+
*/
21+
22+
let myObject = {
23+
name: 'John Doe',
24+
age: 25,
25+
city: 'Example City',
26+
isStudent: true
27+
};
28+
for (let obj in myObject) {
29+
console.log(` key: ${obj} | type: ${typeof myObject[obj]} `);
30+
}

E. Object/select-color.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Problem-1
2+
Access the golden rod color value in output.
3+
4+
const colors = {
5+
red: "#ff0000",
6+
green: "#00ff00",
7+
blue: "#0000ff",
8+
"golden rod": '#daa520'
9+
};
10+
*/
11+
12+
const colors = {
13+
red: "#ff0000",
14+
green: "#00ff00",
15+
blue: "#0000ff",
16+
"golden rod": '#daa520'
17+
};
18+
19+
const goldenRodColor = (colors["golden rod"]);
20+
21+
console.log("This is olden rod color : ", goldenRodColor);

0 commit comments

Comments
 (0)