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 1 commit
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
Prev Previous commit
Next Next commit
Operators task 4 translated
  • Loading branch information
MShafquat committed Jan 16, 2021
commit 27434ba72a0c433e2865439b80f3d723391f9750
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