Skip to content

Commit ea13ff9

Browse files
authored
Merge pull request #43 from Dheyson/master
Functions - Tasks and solutions
2 parents 1d2048c + 90a5d1b commit ea13ff9

File tree

9 files changed

+48
-48
lines changed

9 files changed

+48
-48
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
No difference.
1+
Sem diferença.

1-js/02-first-steps/14-function-basics/1-if-else-required/task.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 4
22

33
---
44

5-
# Is "else" required?
5+
# "else" é obrigatório?
66

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

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

1111
```js
1212
function checkAge(age) {
@@ -15,13 +15,13 @@ function checkAge(age) {
1515
*!*
1616
} else {
1717
// ...
18-
return confirm('Did parents allow you?');
18+
return confirm('Seus pais permitiram?');
1919
}
2020
*/!*
2121
}
2222
```
2323

24-
Will the function work differently if `else` is removed?
24+
A função funcionará diferentemente se `else` for removido?
2525

2626
```js
2727
function checkAge(age) {
@@ -30,9 +30,9 @@ function checkAge(age) {
3030
}
3131
*!*
3232
// ...
33-
return confirm('Did parents allow you?');
33+
return confirm('Seus pais permitiram?');
3434
*/!*
3535
}
3636
```
3737

38-
Is there any difference in the behavior of these two variants?
38+
Existe alguma diferença no comportamento dessas duas variantes?
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
Using a question mark operator `'?'`:
1+
Usando operador de interrogação `'?'`:
22

33
```js
44
function checkAge(age) {
5-
return (age > 18) ? true : confirm('Did parents allow you?');
5+
return (age > 18) ? true : confirm('Seus pais permitiram?');
66
}
77
```
88

9-
Using OR `||` (the shortest variant):
9+
Usando OR `||` (A variante mais curta):
1010

1111
```js
1212
function checkAge(age) {
13-
return (age > 18) || confirm('Did parents allow you?');
13+
return (age > 18) || confirm('Seus pais permitiram?');
1414
}
1515
```
1616

17-
Note that the parentheses around `age > 18` are not required here. They exist for better readabilty.
17+
Note que os parêntesis em volta de `age > 18` não são obrigatórios aqui. Eles existem para melhor legibilidade.

1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ importance: 4
22

33
---
44

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

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

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

1111
```js
1212
function checkAge(age) {
1313
if (age > 18) {
1414
return true;
1515
} else {
16-
return confirm('Do you have your parents permission to access this page?');
16+
return confirm('Você tem permissão de seus pais para acessar esta página?');
1717
}
1818
}
1919
```
2020

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

23-
Make two variants of `checkAge`:
23+
Faça duas variantes de `checkAge`:
2424

25-
1. Using a question mark operator `?`
26-
2. Using OR `||`
25+
1. Usando um operador de interrogação `?`
26+
2. Usando OR `||`

1-js/02-first-steps/14-function-basics/3-min/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
A solution using `if`:
1+
Uma solução usando `if`:
22

33
```js
44
function min(a, b) {
@@ -10,12 +10,12 @@ function min(a, b) {
1010
}
1111
```
1212

13-
A solution with a question mark operator `'?'`:
13+
Uma solução com o operador de interrogação `'?'`:
1414

1515
```js
1616
function min(a, b) {
1717
return a < b ? a : b;
1818
}
1919
```
2020

21-
P.S. In the case of an equality `a == b` it does not matter what to return.
21+
P.S. No caso de igualdade `a == b`, não importa o que retorna.

1-js/02-first-steps/14-function-basics/3-min/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ importance: 1
44

55
# Function min(a, b)
66

7-
Write a function `min(a,b)` which returns the least of two numbers `a` and `b`.
7+
Escreva uma função `min(a,b)` no qual retorna o menor de dois números `a` e `b`.
88

9-
For instance:
9+
Por exemplo:
1010

1111
```js
1212
min(2, 5) == 2

1-js/02-first-steps/14-function-basics/4-pow/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ let x = prompt("x?", '');
1414
let n = prompt("n?", '');
1515

1616
if (n < 1) {
17-
alert(`Power ${n} is not supported,
18-
use an integer greater than 0`);
17+
alert(`Expoente ${n} não é suportado,
18+
use um inteiro maior que 0`);
1919
} else {
2020
alert( pow(x, n) );
2121
}

1-js/02-first-steps/14-function-basics/4-pow/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ importance: 4
22

33
---
44

5-
# Function pow(x,n)
5+
# Função pow(x,n)
66

7-
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.
7+
Escreva uma função `pow(x,n)` que retorna `x` no expoente `n`. Ou, em outras palavras, multiplica `x` por si mesmo `n` vezes e retorna um resultado.
88

99
```js
1010
pow(3, 2) = 3 * 3 = 9
1111
pow(3, 3) = 3 * 3 * 3 = 27
1212
pow(1, 100) = 1 * 1 * ...* 1 = 1
1313
```
1414

15-
Create a web-page that prompts for `x` and `n`, and then shows the result of `pow(x,n)`.
15+
Crie uma página web que solicite `x` e `n`, em seguida, mostre o resultado de `pow(x,n)`.
1616

1717
[demo]
1818

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

1-js/02-first-steps/14-function-basics/article.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
# Functions
1+
# Funções
22

3-
Quite often we need to perform a similar action in many places of the script.
3+
Muitas vezes nós precisamos realizar uma ação semelhante em muitos lugares do script.
44

5-
For example, we need to show a nice-looking message when a visitor logs in, logs out and maybe somewhere else.
5+
Por exemplo, precisamos mostrar uma boa mensagem quando um usuário efetua login, efetua logout e talvez em outro lugar.
66

7-
Functions are the main "building blocks" of the program. They allow the code to be called many times without repetition.
7+
Funções são os principais "building blocks" do programa. Elas permitem que o código sejam chamados muitas vezes sem repetição.
88

9-
We've already seen examples of built-in functions, like `alert(message)`, `prompt(message, default)` and `confirm(question)`. But we can create functions of our own as well.
9+
Nós já vimos exemplos de built-in functions, como `alert(message)`, `prompt(message, default)` e `confirm(question)`. Mas nós podemos criar funções próprias também.
1010

1111
## Function Declaration
1212

13-
To create a function we can use a *function declaration*.
13+
Para criarmos uma função podemos usar uma *function declaration*.
1414

15-
It looks like this:
15+
Se parece assim:
1616

1717
```js
1818
function showMessage() {
19-
alert( 'Hello everyone!' );
19+
alert( 'Olá a todos!' );
2020
}
2121
```
2222

23-
The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* between the parentheses (empty in the example above) and finally the code of the function, also named "the function body", between curly braces.
23+
A palavra-chave `function` vem primeiro, depois vem o *nome da função*, e uma lista de *parâmetros* entre os parêntesis (vazio no exemplo acima) e finalmente o código da função, também chamado de "o corpo da função", entre chaves.
2424

2525
![](function_basics.png)
2626

27-
Our new function can be called by its name: `showMessage()`.
27+
Nossa nova função pode ser chamada pelo seu nome: `showMessage()`.
2828

29-
For instance:
29+
Por exemplo:
3030

3131
```js run
3232
function showMessage() {
33-
alert( 'Hello everyone!' );
33+
alert( 'Olá a todos!' );
3434
}
3535

3636
*!*
@@ -39,13 +39,13 @@ showMessage();
3939
*/!*
4040
```
4141

42-
The call `showMessage()` executes the code of the function. Here we will see the message two times.
42+
A chamada `showMessage()` executa o código da função. Aqui vemos a mensagem duas vezes.
4343

44-
This example clearly demonstrates one of the main purposes of functions: to avoid code duplication.
44+
Este exemplo demonstra claramente um dos principais objetivos das funções: evitar código duplicado.
4545

46-
If we ever need to change the message or the way it is shown, it's enough to modify the code in one place: the function which outputs it.
46+
Se precisarmos mudar a mensagem ou a maneira que ela é mostrada, basta modificar o código em um só lugar: a função que gera isso.
4747

48-
## Local variables
48+
## Variáveis locais
4949

5050
A variable declared inside a function is only visible inside that function.
5151

0 commit comments

Comments
 (0)