Skip to content

Conditional branching: if, '?' #123

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 14 commits into from
May 12, 2022
8 changes: 4 additions & 4 deletions 1-js/02-first-steps/10-ifelse/1-if-zero-string/solution.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
**Yes, it will.**
**Այո, կցուցադրվի:**

Any string except an empty one (and `"0"` is not empty) becomes `true` in the logical context.
Ցանկացած տող, բացի դատարկից (իսկ `"0"`-ն դատարկ չէ) տրամաբանական համատեքստում դառնում է `true`:

We can run and check:
Մենք կարող ենք գործարկել և ստուգել.

```js run
if ("0") {
alert( 'Hello' );
alert( 'Ողջույն' );
}
```

8 changes: 4 additions & 4 deletions 1-js/02-first-steps/10-ifelse/1-if-zero-string/task.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
importance: 5
կարևորությունը՝ 5

---

# if (a string with zero)
# if (զրոյով տող)

Will `alert` be shown?
Կցուցադրվի՞ արդյոք `alert`-ը:

```js
if ("0") {
alert( 'Hello' );
alert( 'Ողջույն' );
}
```

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<script>
'use strict';

let value = prompt('What is the "official" name of JavaScript?', '');
let value = prompt('Ո՞րն է JavaScript-ի «պաշտոնական» անվանումը:', '');

if (value == 'ECMAScript') {
alert('Right!');
alert('Ճիշտ է:');
} else {
alert("You don't know? ECMAScript!");
alert("Դուք չգիտե՞ք. ECMAScript:");
}
</script>

Expand Down
8 changes: 4 additions & 4 deletions 1-js/02-first-steps/10-ifelse/2-check-standard/task.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
importance: 2
կարևորությունը՝ 2

---

# The name of JavaScript
# JavaScript-ի անվանումը

Using the `if..else` construct, write the code which asks: 'What is the "official" name of JavaScript?'
Օգտագործելով `if..else` կառուցվածքը, գրեք կոդ, որը կհարցնի. «Ո՞րն է JavaScript-ի «պաշտոնական» անվանումը:»։

If the visitor enters "ECMAScript", then output "Right!", otherwise -- output: "You don't know? ECMAScript!"
Եթե այցելուն մուտքագրում է «ECMAScript», ապա արտատպեք «Ճիշտ է:», հակառակ դեպքում՝ արտատպեք «Դուք չգիտե՞ք. ECMAScript:»:

![](ifelse_task2.svg)

Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/10-ifelse/3-sign/if_sign/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script>
'use strict';

let value = prompt('Type a number', 0);
let value = prompt('Մուտքագրեք թիվ', 0);

if (value > 0) {
alert(1);
Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/10-ifelse/3-sign/solution.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


```js run
let value = prompt('Type a number', 0);
let value = prompt('Մուտքագրեք թիվ', 0);

if (value > 0) {
alert( 1 );
Expand Down
14 changes: 7 additions & 7 deletions 1-js/02-first-steps/10-ifelse/3-sign/task.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
importance: 2
կարևորությունը՝ 2

---

# Show the sign
# Ցույց տալ նշանը

Using `if..else`, write the code which gets a number via `prompt` and then shows in `alert`:
Օգտագործելով `if..else`՝ գրեք այնպիսի կոդ, որը `prompt`-ի միջոցով ստանում է թիվ և այնուհետև `alert`-ով ցուցադրում է.

- `1`, if the value is greater than zero,
- `-1`, if less than zero,
- `0`, if equals zero.
- `1`, եթե արժեքը մեծ է զրոյից,
- `-1`, եթե փոքր է զրոյից,
- `0`, եթե հավասար է զրոյի։

In this task we assume that the input is always a number.
Այս առաջադրանքում մենք ենթադրում ենք, որ մուտքագրվածը միշտ թիվ է:

[demo src="if_sign"]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


```js
let result = (a + b < 4) ? 'Below' : 'Over';
let result = (a + b < 4) ? 'Ցածր' : 'Բարձր';
```

10 changes: 5 additions & 5 deletions 1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
importance: 5
կարևորությունը՝ 5

---

# Rewrite 'if' into '?'
# «if»-ը փոխարինեք «?»-ով

Rewrite this `if` using the conditional operator `'?'`:
Վերագրեք այս `if`-ը՝ օգտագործելով `'?'` պայմանական օպերատորը.

```js
let result;

if (a + b < 4) {
result = 'Below';
result = 'Ցածր';
} else {
result = 'Over';
result = 'Բարձր';
}
```
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@


```js
let message = (login == 'Employee') ? 'Hello' :
(login == 'Director') ? 'Greetings' :
(login == '') ? 'No login' :
let message = (login == 'Աշխատակից') ? 'Ողջույն' :
(login == 'Տնօրեն') ? 'Ողջույններ' :
(login == '') ? 'Մուտք չկա' :
'';
```

18 changes: 9 additions & 9 deletions 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
importance: 5
կարևորությունը՝ 5

---

# Rewrite 'if..else' into '?'
# «if..else»-ը փոխարինեք «?»-ով:

Rewrite `if..else` using multiple ternary operators `'?'`.
Վերաշարադրեք `if..else`-ը՝ օգտագործելով մի քանի «եռակի» օպերատորներ `?`:

For readability, it's recommended to split the code into multiple lines.
Ընթեռնելիության համար խորհուրդ է տրվում կոդը բաժանել մի քանի տողերի:

```js
let message;

if (login == 'Employee') {
message = 'Hello';
} else if (login == 'Director') {
message = 'Greetings';
if (login == 'Աշխատակից') {
message = 'Ողջույն';
} else if (login == 'Տնօրեն') {
message = 'Ողջույններ';
} else if (login == '') {
message = 'No login';
message = 'Մուտք չկա';
} else {
message = '';
}
Expand Down