Skip to content

Objects #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Oct 27, 2019
17 changes: 8 additions & 9 deletions 1-js/04-object-basics/01-object/2-hello-object/task.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
importance: 5
গুরুত্বঃ ৫

---

# Hello, object
# হ্যালো, অবজেক্ট

Write the code, one line for each action:

1. Create an empty object `user`.
2. Add the property `name` with the value `John`.
3. Add the property `surname` with the value `Smith`.
4. Change the value of the `name` to `Pete`.
5. Remove the property `name` from the object.
নিন্মে বর্ণিত প্রতিটি একশনের জন্য এক একটি লাইনে কোড লিখুনঃ

1. `user` নামে একটি খালি অবজেক্ট তৈরি করুন।
2. `name` নামে একটি প্রোপার্টি `John` ভ্যালু সহ সংযুক্ত করুন।
3. `surname` নামে একটি প্রোপার্টি `Smith` ভ্যালু সহ সংযুক্ত করুন।
4. `name` নামের প্রোপার্টির ভ্যালু পরিবর্তন করে `Pete` রাখুন।
5. `name` নামের প্রোপার্টিটি অবজেক্ট থেকে মুছে দিন।
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function isEmpty(obj) {
for (let key in obj) {
// if the loop has started, there is a property
// যদি লুপ শুরু হয় তাহলে অবজেক্টে প্রোপার্টি আছে
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion 1-js/04-object-basics/01-object/3-is-empty/solution.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Just loop over the object and `return false` immediately if there's at least one property.
অবজেক্টের উপর লুপ চালান এবং যদি কোন প্রোপার্টি পাওয়া যায় সাথে সাথে `return false` করুন।
9 changes: 4 additions & 5 deletions 1-js/04-object-basics/01-object/3-is-empty/task.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
importance: 5
গুরুত্বঃ ৫

---

# Check for emptiness
# খালি কিনা পরীক্ষা করুন

Write the function `isEmpty(obj)` which returns `true` if the object has no properties, `false` otherwise.
একটি ফাংশন `isEmpty(obj)` লিখুন যেটি `true` রিটার্ন করে যদি অবজেক্টে কোন প্রোপার্টি না থাকে, অন্যথায় `false` রিটার্ন করুন।

Should work like that:
কোডটি এভাবে কাজ করা উচিতঃ

```js
let schedule = {};
Expand All @@ -17,4 +17,3 @@ schedule["8:30"] = "get up";

alert( isEmpty(schedule) ); // false
```

10 changes: 5 additions & 5 deletions 1-js/04-object-basics/01-object/4-const-object/solution.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Sure, it works, no problem.
অবশ্যই, কোন সমস্যা ছাড়াই কাজ করে।

The `const` only protects the variable itself from changing.
`const` শুধুমাত্র ওই ভেরিয়েবলকে পরিবর্তন থেকে রক্ষা করে।

In other words, `user` stores a reference to the object. And it can't be changed. But the content of the object can.
অন্যভাবে বললে, `user` অবজেক্টটির একটি রেফারেন্স সংরক্ষণ করে। এবং রেফারেন্স পরিবর্তন করা যাবে না। কিন্তু অবজেক্টের কন্টেন্ট পরিবর্তন করা যাবে।

```js run
const user = {
name: "John"
};

*!*
// works
// কাজ করে
user.name = "Pete";
*/!*

// error
// এরর
user = 123;
```
8 changes: 4 additions & 4 deletions 1-js/04-object-basics/01-object/4-const-object/task.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
importance: 5
গুরুত্বঃ ৫

---

# Constant objects?
# ধ্রুবক / কন্সটেন্ট অবজেক্ট?

Is it possible to change an object declared with `const`? What do you think?
`const` দিয়ে ডিক্লেয়ার করা অবজেক্ট কি পরিবর্তন করা সম্ভব? আপনার কি ধারণা?

```js
const user = {
name: "John"
};

*!*
// does it work?
// এটা কাজ করে?
user.name = "Pete";
*/!*
```
10 changes: 5 additions & 5 deletions 1-js/04-object-basics/01-object/5-sum-object/task.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
importance: 5
গুরুত্বঃ ৫

---

# Sum object properties
# অবজেক্টের প্রোপার্টিগুলো যোগ করা

We have an object storing salaries of our team:
আমাদের অবজেক্টে আমাদের টিমের সবার বেতন রাখা আছেঃ

```js
let salaries = {
Expand All @@ -14,6 +14,6 @@ let salaries = {
}
```

Write the code to sum all salaries and store in the variable `sum`. Should be `390` in the example above.
সব বেতনের যোগফল বের করে `sum` ভেরিয়েবলে রাখার কোড লিখুন। উপরের উদাহরণের যোগফল `390` হওয়া উচিত।

If `salaries` is empty, then the result must be `0`.
যদি `salaries` খালি হয়, তাহলে ফলাফল `0` হতে হবে।
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ let menu = {


function multiplyNumeric(obj) {
/* your code */

/* আপনার কোড এখানে লিখুন */

}

multiplyNumeric(menu);

alert( "menu width=" + menu.width + " height=" + menu.height + " title=" + menu.title );

18 changes: 8 additions & 10 deletions 1-js/04-object-basics/01-object/8-multiply-numeric/task.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
importance: 3
গুরুত্বঃ ৩

---

# Multiply numeric properties by 2
# যেসব প্রোপার্টি ভ্যালু একটি সংখ্যা তাদের `2` দিয়ে গুন করুন

Create a function `multiplyNumeric(obj)` that multiplies all numeric properties of `obj` by `2`.
একটি ফাংশন `multiplyNumeric(obj)` লিখুন যেটি `obj` এর সব সংখ্যাভিত্তিক/numeric প্রোপার্টিগুলো কে `2` দিয়ে গুন করে।

For instance:
উদাহরণস্বরূপঃ

```js
// before the call
// কল করার আগে
let menu = {
width: 200,
height: 300,
Expand All @@ -18,16 +18,14 @@ let menu = {

multiplyNumeric(menu);

// after the call
// কল করার পর
menu = {
width: 400,
height: 600,
title: "My menu"
};
```

Please note that `multiplyNumeric` does not need to return anything. It should modify the object in-place.

P.S. Use `typeof` to check for a number here.

মনে রাখবেন `multiplyNumeric` এর কিছুই রিটার্ন করার দরকার নেই। এটা শুধুই অবজেক্টকে ইন-প্লেস পরিবর্তন করবে।

পুনশ্চঃ `typeof` ব্যবহার করে নাম্বার কিনা পরীক্ষা করুন।
Loading