Skip to content

Functions - Local variables and outer variables headers #48

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 4 commits into from
Aug 13, 2024
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,3 +1,3 @@
No difference!
Nenhuma diferença!

In both cases, `return confirm('Did parents allow you?')` executes exactly when the `if` condition is falsy.
Em ambos os casos, `return confirm('Seus pais permitiram?')` é executado exatamente quando a condição `if` é falsa.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 4

---

# Is "else" required?
# "else" é obrigatório?

The following function returns `true` if the parameter `age` is greater than `18`.
A função a seguir retorna `true` se o parâmetro `age` for maior que `18`.

Otherwise it asks for a confirmation and returns its result:
Caso contrário, ele pede uma confirmação e retorna seu resultado:

```js
function checkAge(age) {
Expand All @@ -15,13 +15,13 @@ function checkAge(age) {
*!*
} else {
// ...
return confirm('Did parents allow you?');
return confirm('Seus pais permitiram?');
}
*/!*
}
```

Will the function work differently if `else` is removed?
A função funcionará de forma diferente se `else` for removido?

```js
function checkAge(age) {
Expand All @@ -30,9 +30,9 @@ function checkAge(age) {
}
*!*
// ...
return confirm('Did parents allow you?');
return confirm('Seus pais permitiram?');
*/!*
}
```

Is there any difference in the behavior of these two variants?
Existe alguma diferença no comportamento dessas duas variantes?
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Using a question mark operator `'?'`:
Usando o operador de ponto de interrogação `'?'`:

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

Using OR `||` (the shortest variant):
Usando OR `||` (a variante mais curta):

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

Note that the parentheses around `age > 18` are not required here. They exist for better readability.
Observe que os parênteses em torno de `age > 18` não são necessários aqui. Eles existem para melhor legibilidade.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ importance: 4

---

# Rewrite the function using '?' or '||'
# Reescreva a função usando '?' ou '||'

The following function returns `true` if the parameter `age` is greater than `18`.
A função a seguir retorna `true` se o parâmetro `age` for maior que `18`.

Otherwise it asks for a confirmation and returns its result.
Caso contrário, ele pede uma confirmação e retorna seu resultado.

```js
function checkAge(age) {
if (age > 18) {
return true;
} else {
return confirm('Did parents allow you?');
return confirm('Seus pais permitiram?');
}
}
```

Rewrite it, to perform the same, but without `if`, in a single line.
Reescreva-o, para executar o mesmo, mas sem `if`, em uma única linha.

Make two variants of `checkAge`:
Faça duas variantes de `checkAge`:

1. Using a question mark operator `?`
2. Using OR `||`
1. Usando o operador de ponto de interrogação `?`
2. Usando OR `||`
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/15-function-basics/4-pow/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ importance: 4

# Function 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.
Escreva uma função `pow(x,n)` que retorna `x` na potência `n`. Ou, em outras palavras, multiplica `x` por ele mesmo `n` vezes e retorna o resultado.

```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)`.
Crie uma página da Web que solicite `x` e `n` e mostre o resultado de `pow(x,n)`.

[demo]

P.S. In this task the function should support only natural values of `n`: integers up from `1`.
PS Nesta tarefa, a função deve suportar apenas valores naturais de `n`: inteiros acima de `1`.
Loading