Skip to content

Basic operators, maths #113

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 8 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions 1-js/02-first-steps/08-operators/1-increment-order/solution.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

The answer is:
উত্তর হচ্ছে:

- `a = 2`
- `b = 2`
Expand All @@ -9,10 +9,10 @@ The answer is:
```js run no-beautify
let a = 1, b = 1;

alert( ++a ); // 2, prefix form returns the new value
alert( b++ ); // 1, postfix form returns the old value
alert( ++a ); // 2, প্রিফিক্স ফর্ম নতুন ভ্যালু রিটার্ন করে
alert( b++ ); // 1, পোস্টফিক্স ফর্ম পুরনো ভ্যালু রিটার্ন করে

alert( a ); // 2, incremented once
alert( b ); // 2, incremented once
alert( a ); // 2, একবার বৃদ্ধি পেয়েছে
alert( b ); // 2, একবার বৃদ্ধি পেয়েছে
```

4 changes: 2 additions & 2 deletions 1-js/02-first-steps/08-operators/1-increment-order/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 5

---

# The postfix and prefix forms
# পোস্টফিক্স এবং প্রিফিক্স ফর্ম

What are the final values of all variables `a`, `b`, `c` and `d` after the code below?
নিচের কোডে `a`, `b`, `c` `d` এর ফাইনাল ভ্যালু কী হবে?

```js
let a = 1, b = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The answer is:
উত্তর হচ্ছে:

- `a = 4` (multiplied by 2)
- `x = 5` (calculated as 1 + 4)
- `a = 4` (২ দিয়ে গুণ)
- `x = 5` (১ + ৪ হিসেবে)

4 changes: 2 additions & 2 deletions 1-js/02-first-steps/08-operators/2-assignment-result/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 3

---

# Assignment result
# অ্যাসাইনমেন্টের ফলাফল

What are the values of `a` and `x` after the code below?
নিচের কোডে `a` এবং `x` এর মান কী হবে?

```js
let a = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ undefined + 1 = NaN // (6)
1. কোন স্ট্রিংয়ের সাথে যোগের ক্ষেত্রে `"" + 1` তে `1` রূপান্তর হয়ে `"" + 1 = "1"` হয়। তাই এখানে পায় `"1" + 0`, এক্ষেত্রেও একই নিয়ম প্রযোজ্য।
2. বিয়োগ `-` (প্রায় অন্যসব অপারেটরের মতই) শুধুমাত্র সংখ্যা নিয়ে কাজ করে, এটি ফাঁকা স্ট্রিংকে শূন্য তে রূপান্তর করে নেয় `""` থেকে `0` হবে।
3. স্ট্রিং সংযুক্তকরণ নীতি অনুসারে `5` স্ট্রিংয়ে রূপান্তর হবে।
4. বিয়োগের সময় স্ট্রিং সবসময় সংখ্যায় রূপান্তর হয়, তাই এক্ষেত্রে `" -9 "` সংখ্যা `-9` তে পরিবর্তন হয় (এখানে স্পেসগুলিকে উপেক্ষা করে )
4. বিয়োগের সময় স্ট্রিং সবসময় সংখ্যায় রূপান্তর হয়, তাই এক্ষেত্রে `" -9 "` সংখ্যা `-9` তে পরিবর্তন হয় (এখানে স্পেসগুলিকে উপেক্ষা করে)।
5. `null` হবে `0` সংখ্যায় রুপান্তরের পর।
6. `undefined` হয়ে যায় `NaN` সংখ্যায় রূপান্তর করা হলে।
7. স্পেসসমূহ বাদ দেয়া হয় সংখ্যায় রুপান্তর করলে, এখানে পুরো স্ট্রিংটাই বিভিন্ন স্পেসে তৈরি, যেমনঃ `\t`, `\n` এবং তাদের মাঝের "রেগুলার" স্পেসসমূহ। সুতরাং এটি ফাঁকা স্ট্রিংয়ের মতই, যা শুন্যতে (`0`) রুপান্তর হয়।
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ undefined + 1
" \t \n" - 2
```

ভালো করে ভাবুন, লিখে রাখুন এবং আমদের উত্তরের সাথে মিলিয়ে দেখুন।
ভালো করে ভাবুন, লিখে রাখুন এবং আমাদের উত্তরের সাথে মিলিয়ে দেখুন।
12 changes: 6 additions & 6 deletions 1-js/02-first-steps/08-operators/4-fix-prompt/solution.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The reason is that prompt returns user input as a string.
কারণ prompt ইউজার ইনপুটকে স্ট্রিং হিসেবে রিটার্ন করে।

So variables have values `"1"` and `"2"` respectively.
তাই ভ্যারিয়েবল দুটোর ভ্যালু হচ্ছে যথাক্রমে `"1"` এবং `"2"`

```js run
let a = "1"; // prompt("First number?", 1);
Expand All @@ -9,9 +9,9 @@ let b = "2"; // prompt("Second number?", 2);
alert(a + b); // 12
```

What we should do is to convert strings to numbers before `+`. For example, using `Number()` or prepending them with `+`.
আমাদের `+` এর আগে স্ট্রিংকে নাম্বারে রূপান্তর করে নেয়া উচিৎ। যেমন, `Number()` ব্যবহার করে বা আগে `+` বসিয়ে।

For example, right before `prompt`:
যেমন একদম `prompt` এর আগে:

```js run
let a = +prompt("First number?", 1);
Expand All @@ -20,7 +20,7 @@ let b = +prompt("Second number?", 2);
alert(a + b); // 3
```

Or in the `alert`:
অথবা `alert`:

```js run
let a = prompt("First number?", 1);
Expand All @@ -29,4 +29,4 @@ let b = prompt("Second number?", 2);
alert(+a + +b); // 3
```

Using both unary and binary `+` in the latest code. Looks funny, doesn't it?
শেষ কোডে ইউনারি আর বাইনারি `+` দুটোই আছে। মজার দেখাচ্ছে, তাই না?
8 changes: 4 additions & 4 deletions 1-js/02-first-steps/08-operators/4-fix-prompt/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 5

---

# Fix the addition
# যোগটি ঠিক করুন

Here's a code that asks the user for two numbers and shows their sum.
নিচের কোডটি ইউজারের কাছ থেকে দুটি সংখ্যা নিয়ে তাদের যোগফল দেখায়।

It works incorrectly. The output in the example below is `12` (for default prompt values).
এটা ঠিকমতো কাজ করছে না। নিচের উদাহরণে আউটপুট আসছে `12` (ডিফল্ট prompt ভ্যালুর জন্য)।

Why? Fix it. The result should be `3`.
কেন? এটি ঠিক করুন। ফলাফল `3` হওয়া উচিৎ।

```js run
let a = prompt("First number?", 1);
Expand Down
Loading