-
Notifications
You must be signed in to change notification settings - Fork 31
Functions #169
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
base: master
Are you sure you want to change the base?
Functions #169
Changes from 1 commit
f114998
ad10bf3
b6ba903
981af4d
d6ace89
cd59785
0101de4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
No difference. | ||
Nicio diferenta. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
Using a question mark operator `'?'`: | ||
Folosind un operator de semn de întrebare `'?'`: | ||
|
||
```js | ||
function checkAge(age) { | ||
return (age > 18) ? true : confirm('Did parents allow you?'); | ||
return (age > 18) ? true : confirm('Ți-au permis părinții?'); | ||
} | ||
``` | ||
|
||
Using OR `||` (the shortest variant): | ||
Folosind SAU `||` (cea mai scurtă variantă): | ||
|
||
```js | ||
function checkAge(age) { | ||
return (age > 18) || confirm('Did parents allow you?'); | ||
return (age > 18) || confirm('Ți-au permis părinții?'); | ||
} | ||
``` | ||
|
||
Note that the parentheses around `age > 18` are not required here. They exist for better readability. | ||
Rețineți că parantezele din jurul `age > 18` nu sunt necesare aici. Ele există pentru o mai bună lizibilitate. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,25 +2,25 @@ importance: 4 | |||||
|
||||||
--- | ||||||
|
||||||
# Rewrite the function using '?' or '||' | ||||||
# Rescrieți funcția folosind '?' sau '||' | ||||||
|
||||||
The following function returns `true` if the parameter `age` is greater than `18`. | ||||||
Următoarea funcție returnează `true` dacă parametrul `age` este mai mare decât `18`. | ||||||
|
||||||
Otherwise it asks for a confirmation and returns its result. | ||||||
În caz contrar, solicită o confirmare și returnează rezultatul. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```js | ||||||
function checkAge(age) { | ||||||
if (age > 18) { | ||||||
return true; | ||||||
} else { | ||||||
return confirm('Did parents allow you?'); | ||||||
return confirm('Ți-au permis părinții?'); | ||||||
} | ||||||
} | ||||||
``` | ||||||
|
||||||
Rewrite it, to perform the same, but without `if`, in a single line. | ||||||
Rescrie-l, pentru a efectua la fel, dar fără `if`, într-o singură linie. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Make two variants of `checkAge`: | ||||||
Faceți două variante de `checkAge`: | ||||||
|
||||||
1. Using a question mark operator `?` | ||||||
2. Using OR `||` | ||||||
1. Folosind un operator de semn de întrebare `?` | ||||||
2. Folosind SAU `||` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,7 +14,7 @@ let x = prompt("x?", ''); | |||||
let n = prompt("n?", ''); | ||||||
|
||||||
if (n < 1) { | ||||||
alert(`Power ${n} is not supported, use a positive integer`); | ||||||
alert(`Puterea ${n} nu este acceptată, utilizați un număr întreg pozitiv`); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am putea folosi
Suggested change
|
||||||
} else { | ||||||
alert( pow(x, n) ); | ||||||
} | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.