Skip to content

Functions #29

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 10 commits into from Nov 15, 2019
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
Original file line number Diff line number Diff line change
@@ -1 +1 @@
No difference.
পার্থক্য নেই.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 4

---

# Is "else" required?
# "else" কি দরকারি?

The following function returns `true` if the parameter `age` is greater than `18`.
নিচের ফাংশন `true` রিটার্ন করে যদি প্যারামিটার `age` `18` এর চেয়ে বড় হয়।

Otherwise it asks for a confirmation and returns its result:
নতুবা এটা কনফার্মেশন চায় ও ভ্যালু রিটার্ন করে।

```js
function checkAge(age) {
Expand All @@ -21,7 +21,7 @@ function checkAge(age) {
}
```

Will the function work differently if `else` is removed?
`else` না থাকলে কি ফাংশন আগের মতো কাজ করবে?

```js
function checkAge(age) {
Expand All @@ -35,4 +35,4 @@ function checkAge(age) {
}
```

Is there any difference in the behavior of these two variants?
দুই ফাংশনের মধ্যে কোনো কাজের পার্থক্য আছে কি?
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Using a question mark operator `'?'`:
প্রশ্নবোধক চিহ্ন `'?'` ব্যবহার করেঃ

```js
function checkAge(age) {
return (age > 18) ? true : confirm('Did parents allow you?');
}
```

Using OR `||` (the shortest variant):
OR `||` ব্যবহার করে (সবচেয়ে ছোট):

```js
function checkAge(age) {
return (age > 18) || confirm('Did parents allow you?');
}
```

Note that the parentheses around `age > 18` are not required here. They exist for better readabilty.
নোটঃ `age > 18` দুপাশে প্রথম ব্রাকেট প্রয়োজনীয় না। শুধুই বুঝার সুবিধার্থে দেওয়া।
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 4

---

# Rewrite the function using '?' or '||'
# '?' অথবা '||' এর ব্যবহার

The following function returns `true` if the parameter `age` is greater than `18`.
নিচের ফাংশন `true` রিটার্ন করে যদি `age` `18` এর চেয়ে বড় হয়।

Otherwise it asks for a confirmation and returns its result.
নতুবা এটা কনফার্মেশন চায় ও ভ্যালু রিটার্ন করে।

```js
function checkAge(age) {
Expand All @@ -18,9 +18,9 @@ function checkAge(age) {
}
```

Rewrite it, to perform the same, but without `if`, in a single line.
এটাকে পূনরায় লিখুন, যেন ফাংশন একই কাজ করে, কিন্তু সম্পুর্ণভাবে `if` ছাড়া।

Make two variants of `checkAge`:
`checkAge` এর দুইটা ভিন্ন ফাংশন বানান, যা একই কাজ করবেঃ

1. Using a question mark operator `?`
2. Using OR `||`
1. প্রশ্নবোধক `?` চিহ্ন ব্যবহার করে
2. OR `||` ব্যবহার করে
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/14-function-basics/3-min/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
A solution using `if`:
`if` ব্যবহার করে সমাধানঃ

```js
function min(a, b) {
Expand All @@ -10,12 +10,12 @@ function min(a, b) {
}
```

A solution with a question mark operator `'?'`:
`'?'` ব্যবহার করে সমাধানঃ

```js
function min(a, b) {
return a < b ? a : b;
}
```

P.S. In the case of an equality `a == b` it does not matter what to return.
নোটঃ সমানের ক্ষেত্রে `a == b` কী রিটার্ন করা লাগবে সে বিষয়ে সমস্যাতে কিছু বলা হয়নি।
13 changes: 6 additions & 7 deletions 1-js/02-first-steps/14-function-basics/3-min/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ importance: 1

---

# Function min(a, b)
# min(a, b) ফাংশন

Write a function `min(a,b)` which returns the least of two numbers `a` and `b`.
একটা ফাংশন লিখুন `min(a,b)` যা সবচেয়ে ছোট ভ্যালু রিটার্ন করবে `a` `b` এর মধ্যে থেকে।

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

```js
min(2, 5) == 2
min(3, -1) == -1
min(1, 1) == 1
min(2, 5) == 2;
min(3, -1) == -1;
min(1, 1) == 1;
```

8 changes: 4 additions & 4 deletions 1-js/02-first-steps/14-function-basics/4-pow/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ importance: 4

---

# Function pow(x,n)
# pow(x,n) ফাংশন

Write a function `pow(x,n)` that returns `x` in power `n`. Or, in other words, multiplies `x` by itself `n` times and returns the result.
একটা ফাংশন লিখুন `pow(x,n)` যা ভ্যালু রিটার্ন করে `x` এর পাওয়ার `n` ধরে। অন্যভাবে, `x` কে `n` বার গুণ করে ফলাফল রিটার্ন করে।

```js
pow(3, 2) = 3 * 3 = 9
pow(3, 3) = 3 * 3 * 3 = 27
pow(1, 100) = 1 * 1 * ...* 1 = 1
```

Create a web-page that prompts for `x` and `n`, and then shows the result of `pow(x,n)`.
একটা ওয়েব পেইজ বানান যেখান থেকে ইউজারের কাছ থেকে `x` `n` নেওয়া যাবে, সেখান থেকে `pow(x,n)` এর ভ্যালু রিটার্ন করুন।

[demo]

P.S. In this task the function should support only natural values of `n`: integers up from `1`.
নোটঃ এই ক্ষেত্রে `n` এর মান স্বাভাবিক হওয়া উচিৎ: ইন্টিজার `1` বা তার বেশি।
Loading