Skip to content

Commit 1fccebf

Browse files
authored
Update article.md
1 parent 89bc194 commit 1fccebf

File tree

1 file changed

+51
-50
lines changed

1 file changed

+51
-50
lines changed

1-js/02-first-steps/10-ifelse/article.md

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -40,78 +40,78 @@ Let's recall the conversion rules from the chapter <info:type-conversions>:
4040
- A number `0`, an empty string `""`, `null`, `undefined`, and `NaN` all become `false`. Because of that they are called "falsy" values.
4141
- Other values become `true`, so they are called "truthy".
4242

43-
So, the code under this condition would never execute:
43+
Ошондо, мындай шарттан кийин кеткен код эч качан аткарылбайт:
4444

4545
```js
4646
if (0) { // 0 бул жалган
4747
...
4848
}
4949
```
5050

51-
...and inside this condition -- it always will:
51+
...жана мындай шарттан кийин ал ар дайым аткарылат:
5252

5353
```js
5454
if (1) { // 1 бул чындык
5555
...
5656
}
5757
```
5858

59-
We can also pass a pre-evaluated boolean value to `if`, like this:
59+
Биз ошондой эле алдын ала айландырылган логикалык маанини `if`ге өткөрө алабыз, мисалы:
6060

6161
```js
62-
let cond = (year == 2015); // equality evaluates to true or false
62+
let cond = (year == 2015); // теңештирүү true же false'го айланат
6363

6464
if (cond) {
6565
...
6666
}
6767
```
6868

69-
## The "else" clause
69+
## "else" пункту
7070

71-
The `if` statement may contain an optional "else" block. It executes when the condition is falsy.
71+
`if` нускамасы кошумча "else" блогун камтышы мүмкүн. Шарт жалган болгондо ал аткарылат.
7272

73-
For example:
73+
Мисалы:
7474
```js run
75-
let year = prompt('In which year was the ECMAScript-2015 specification published?', '');
75+
let year = prompt('ECMAScript-2015 спецификациясы кайсы жылы жарыяланган?', '');
7676

7777
if (year == 2015) {
78-
alert( 'You guessed it right!' );
78+
alert( 'Туура таптыңыз!' );
7979
} else {
80-
alert( 'How can you be so wrong?' ); // any value except 2015
80+
alert( 'Кантип ушунчалык ката кетиресиз?' ); // 2015-тен башкасы
8181
}
8282
```
8383

84-
## Several conditions: "else if"
84+
## Бир нече шарт түзүү: "else if"
8585

86-
Sometimes, we'd like to test several variants of a condition. The `else if` clause lets us do that.
86+
Кээде биз шарттын бир нече варианттарын сынагыбыз келет. `else if` пункту бизге муну кылууга жол берет.
8787

88-
For example:
88+
Мисалы:
8989

9090
```js run
91-
let year = prompt('In which year was the ECMAScript-2015 specification published?', '');
91+
let year = prompt('ECMAScript-2015 спецификациясы кайсы жылы жарыяланган?', '');
9292

9393
if (year < 2015) {
94-
alert( 'Too early...' );
94+
alert( 'Өтө эрте...' );
9595
} else if (year > 2015) {
96-
alert( 'Too late' );
96+
alert( 'Өтө кеч' );
9797
} else {
98-
alert( 'Exactly!' );
98+
alert( 'Дал ошондой!' );
9999
}
100100
```
101101

102102
In the code above, JavaScript first checks `year < 2015`. If that is falsy, it goes to the next condition `year > 2015`. If that is also falsy, it shows the last `alert`.
103103

104-
There can be more `else if` blocks. The final `else` is optional.
104+
`else if` блоктору көбүрөөк болушу мүмкүн. Эң акыркы `else` кошумча болуп саналат.
105105

106-
## Conditional operator '?'
106+
## Шарттык оператор '?'
107107

108-
Sometimes, we need to assign a variable depending on a condition.
108+
Кээде биз шартка көз каранды болгон өзгөрмө ыйгарышыбыз керек.
109109

110-
For instance:
110+
Мисалы үчүн:
111111

112112
```js run no-beautify
113113
let accessAllowed;
114-
let age = prompt('How old are you?', '');
114+
let age = prompt('Сиз канча жаштасыз?', '');
115115

116116
*!*
117117
if (age > 18) {
@@ -124,18 +124,18 @@ if (age > 18) {
124124
alert(accessAllowed);
125125
```
126126

127-
The so-called "conditional" or "question mark" operator lets us do that in a shorter and simpler way.
127+
"Шарттык" же "суроо белгиси" деп аталган оператор жогорудагы шартты кыскараак жана жөнөкөй жол менен жасоого жол берет.
128128

129129
The operator is represented by a question mark `?`. Sometimes it's called "ternary", because the operator has three operands. It is actually the one and only operator in JavaScript which has that many.
130130

131-
The syntax is:
131+
Анын жазылышы:
132132
```js
133133
let result = condition ? value1 : value2;
134134
```
135135

136-
The `condition` is evaluated: if it's truthy then `value1` is returned, otherwise -- `value2`.
136+
`condition` мындай эсептелинет: эгерде ал чындык болсо `value1` кайтарылат, болбосо -- `value2`.
137137

138-
For example:
138+
Мисалы:
139139

140140
```js
141141
let accessAllowed = (age > 18) ? true : false;
@@ -162,18 +162,18 @@ let accessAllowed = age > 18;
162162
```
163163
````
164164

165-
## Multiple '?'
165+
## Бир нече '?'
166166

167-
A sequence of question mark operators `?` can return a value that depends on more than one condition.
167+
Суроо белгиси операторлорунун `?` ырааттуулугу бирден ашык шартка көз каранды болгон маанини кайтара алат.
168168

169-
For instance:
169+
Мисалы үчүн:
170170
```js run
171-
let age = prompt('age?', 18);
171+
let age = prompt('жашыңыз?', 18);
172172

173-
let message = (age < 3) ? 'Hi, baby!' :
174-
(age < 18) ? 'Hello!' :
175-
(age < 100) ? 'Greetings!' :
176-
'What an unusual age!';
173+
let message = (age < 3) ? 'Салам, балакай!' :
174+
(age < 18) ? 'Салам!' :
175+
(age < 100) ? 'Саламатсызбы!' :
176+
'Жашыңыз кандай укмуштуу!';
177177

178178
alert( message );
179179
```
@@ -186,54 +186,55 @@ It may be difficult at first to grasp what's going on. But after a closer look,
186186
4. If that's true -- it returns `'Greetings!'`. Otherwise, it continues to the expression after the last colon '":"', returning `'What an unusual age!'`.
187187

188188
Here's how this looks using `if..else`:
189+
Мында `if..else` колдонгондон кийинки көрүнүшү:
189190

190191
```js
191192
if (age < 3) {
192-
message = 'Hi, baby!';
193+
message = 'Салам, балакай!';
193194
} else if (age < 18) {
194-
message = 'Hello!';
195+
message = 'Салам!';
195196
} else if (age < 100) {
196-
message = 'Greetings!';
197+
message = 'Саламатсызбы!';
197198
} else {
198-
message = 'What an unusual age!';
199+
message = 'Жашыңыз кандай укмуштуу!';
199200
}
200201
```
201202

202-
## Non-traditional use of '?'
203+
## '?' белгисинин адатсыз колдонушу
203204

204-
Sometimes the question mark `?` is used as a replacement for `if`:
205+
Кээде суроо белгиси `?` - `if`'ти алмаштыруучу катары колдонулат:
205206

206207
```js run no-beautify
207-
let company = prompt('Which company created JavaScript?', '');
208+
let company = prompt('Кайсы компания JavaScript'ти түзгөн?', '');
208209
209210
*!*
210211
(company == 'Netscape') ?
211-
alert('Right!') : alert('Wrong.');
212+
alert('Туура!') : alert('Туура эмес.');
212213
*/!*
213214
```
214215
215-
Depending on the condition `company == 'Netscape'`, either the first or the second expression after the `?` gets executed and shows an alert.
216+
`company == 'Netscape'` шартына жараша, `?` белгисинен кийинки биринчи же экинчи туюнтма аткарылып, билдирүү көрсөтүлөт.
216217
217-
We don't assign a result to a variable here. Instead, we execute different code depending on the condition.
218+
Бул жерде натыйжаны өзгөрмөгө ыйгарбайбыз. Анын ордуна, шартка жараша ар кандай кодду аткарабыз.
218219
219-
**It's not recommended to use the question mark operator in this way.**
220+
**Суроо белгиси операторун мындай колдонгону сунушталбайт.**
220221
221222
The notation is shorter than the equivalent `if` statement, which appeals to some programmers. But it is less readable.
222223
223224
Here is the same code using `if` for comparison:
224225
225226
```js run no-beautify
226-
let company = prompt('Which company created JavaScript?', '');
227+
let company = prompt('Кайсы компания JavaScript'ти түзгөн?', '');
227228

228229
*!*
229230
if (company == 'Netscape') {
230-
alert('Right!');
231+
alert('Туура!');
231232
} else {
232-
alert('Wrong.');
233+
alert('Туура эмес.');
233234
}
234235
*/!*
235236
```
236237
237-
Our eyes scan the code vertically. Code blocks which span several lines are easier to understand than a long, horizontal instruction set.
238+
Биздин көзүбүз кодду өйдөдөн ылдый көрөт. Бир нече саптардан турган код блокторун узун, горизонталдуу нускамаларга караганда түшүнүүгө оңой.
238239
239-
The purpose of the question mark operator `?` is to return one value or another depending on its condition. Please use it for exactly that. Use `if` when you need to execute different branches of code.
240+
Суроо белгиси операторунун `?` максаты – анын шартына жараша тигил же бул маанини кайтаруу. Сураныч, аны дал ушул үчүн колдонуңуз. Коддун ар кандай бутактарын аткарыш керек болгондо `if` колдонуңуз.

0 commit comments

Comments
 (0)