diff --git a/1-js/02-first-steps/14-function-basics/1-if-else-required/solution.md b/1-js/02-first-steps/14-function-basics/1-if-else-required/solution.md index e41c80418..023257922 100644 --- a/1-js/02-first-steps/14-function-basics/1-if-else-required/solution.md +++ b/1-js/02-first-steps/14-function-basics/1-if-else-required/solution.md @@ -1 +1 @@ -No difference. \ No newline at end of file +Sem diferença. diff --git a/1-js/02-first-steps/14-function-basics/1-if-else-required/task.md b/1-js/02-first-steps/14-function-basics/1-if-else-required/task.md index 4f69a5c8c..8557afa9c 100644 --- a/1-js/02-first-steps/14-function-basics/1-if-else-required/task.md +++ b/1-js/02-first-steps/14-function-basics/1-if-else-required/task.md @@ -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` é maior que `18`. -Otherwise it asks for a confirmation and returns its result: +Caso contrário, pede uma confirmação e retorna seu resultado: ```js function checkAge(age) { @@ -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á diferentemente se `else` for removido? ```js function checkAge(age) { @@ -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? diff --git a/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/solution.md b/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/solution.md index c8ee9618f..fb1cf01ae 100644 --- a/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/solution.md +++ b/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/solution.md @@ -1,17 +1,17 @@ -Using a question mark operator `'?'`: +Usando operador 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 readabilty. +Note que os parêntesis em volta de `age > 18` não são obrigatórios aqui. Eles existem para melhor legibilidade. diff --git a/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md b/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md index 523bb127a..f59647409 100644 --- a/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md +++ b/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md @@ -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` é maior que `18`. -Otherwise it asks for a confirmation and returns its result. +Caso contrário, pede por uma confirmação e retorna seu resultado. ```js function checkAge(age) { if (age > 18) { return true; } else { - return confirm('Do you have your parents permission to access this page?'); + return confirm('Você tem permissão de seus pais para acessar esta página?'); } } ``` -Rewrite it, to perform the same, but without `if`, in a single line. +Reescreva, para executar a mesma, 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 um operador de interrogação `?` +2. Usando OR `||` diff --git a/1-js/02-first-steps/14-function-basics/3-min/solution.md b/1-js/02-first-steps/14-function-basics/3-min/solution.md index 2236d9203..093656ebd 100644 --- a/1-js/02-first-steps/14-function-basics/3-min/solution.md +++ b/1-js/02-first-steps/14-function-basics/3-min/solution.md @@ -1,4 +1,4 @@ -A solution using `if`: +Uma solução usando `if`: ```js function min(a, b) { @@ -10,7 +10,7 @@ function min(a, b) { } ``` -A solution with a question mark operator `'?'`: +Uma solução com o operador de interrogação `'?'`: ```js function min(a, b) { @@ -18,4 +18,4 @@ function min(a, b) { } ``` -P.S. In the case of an equality `a == b` it does not matter what to return. \ No newline at end of file +P.S. No caso de igualdade `a == b`, não importa o que retorna. diff --git a/1-js/02-first-steps/14-function-basics/3-min/task.md b/1-js/02-first-steps/14-function-basics/3-min/task.md index 50edd0d36..3bdab4db4 100644 --- a/1-js/02-first-steps/14-function-basics/3-min/task.md +++ b/1-js/02-first-steps/14-function-basics/3-min/task.md @@ -4,9 +4,9 @@ importance: 1 # Function min(a, b) -Write a function `min(a,b)` which returns the least of two numbers `a` and `b`. +Escreva uma função `min(a,b)` no qual retorna o menor de dois números `a` e `b`. -For instance: +Por exemplo: ```js min(2, 5) == 2 diff --git a/1-js/02-first-steps/14-function-basics/4-pow/solution.md b/1-js/02-first-steps/14-function-basics/4-pow/solution.md index 5ef20c386..1db536294 100644 --- a/1-js/02-first-steps/14-function-basics/4-pow/solution.md +++ b/1-js/02-first-steps/14-function-basics/4-pow/solution.md @@ -14,8 +14,8 @@ let x = prompt("x?", ''); let n = prompt("n?", ''); if (n < 1) { - alert(`Power ${n} is not supported, - use an integer greater than 0`); + alert(`Expoente ${n} não é suportado, + use um inteiro maior que 0`); } else { alert( pow(x, n) ); } diff --git a/1-js/02-first-steps/14-function-basics/4-pow/task.md b/1-js/02-first-steps/14-function-basics/4-pow/task.md index f569320c7..f75772567 100644 --- a/1-js/02-first-steps/14-function-basics/4-pow/task.md +++ b/1-js/02-first-steps/14-function-basics/4-pow/task.md @@ -2,9 +2,9 @@ importance: 4 --- -# Function pow(x,n) +# Função 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` no expoente `n`. Ou, em outras palavras, multiplica `x` por si mesmo `n` vezes e retorna um resultado. ```js pow(3, 2) = 3 * 3 = 9 @@ -12,8 +12,8 @@ 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 web que solicite `x` e `n`, em seguida, 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`. +P.S. Nesta tarefa, a função deve suportar apenas valores naturais de `n`: inteiros acima de` 1`. diff --git a/1-js/02-first-steps/14-function-basics/article.md b/1-js/02-first-steps/14-function-basics/article.md index 18833cbf1..f13127a16 100644 --- a/1-js/02-first-steps/14-function-basics/article.md +++ b/1-js/02-first-steps/14-function-basics/article.md @@ -1,36 +1,36 @@ -# Functions +# Funções -Quite often we need to perform a similar action in many places of the script. +Muitas vezes nós precisamos realizar uma ação semelhante em muitos lugares do script. -For example, we need to show a nice-looking message when a visitor logs in, logs out and maybe somewhere else. +Por exemplo, precisamos mostrar uma boa mensagem quando um usuário efetua login, efetua logout e talvez em outro lugar. -Functions are the main "building blocks" of the program. They allow the code to be called many times without repetition. +Funções são os principais "building blocks" do programa. Elas permitem que o código sejam chamados muitas vezes sem repetição. -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. +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. ## Function Declaration -To create a function we can use a *function declaration*. +Para criarmos uma função podemos usar uma *function declaration*. -It looks like this: +Se parece assim: ```js function showMessage() { - alert( 'Hello everyone!' ); + alert( 'Olá a todos!' ); } ``` -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. +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. ![](function_basics.png) -Our new function can be called by its name: `showMessage()`. +Nossa nova função pode ser chamada pelo seu nome: `showMessage()`. -For instance: +Por exemplo: ```js run function showMessage() { - alert( 'Hello everyone!' ); + alert( 'Olá a todos!' ); } *!* @@ -39,13 +39,13 @@ showMessage(); */!* ``` -The call `showMessage()` executes the code of the function. Here we will see the message two times. +A chamada `showMessage()` executa o código da função. Aqui vemos a mensagem duas vezes. -This example clearly demonstrates one of the main purposes of functions: to avoid code duplication. +Este exemplo demonstra claramente um dos principais objetivos das funções: evitar código duplicado. -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. +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. -## Local variables +## Variáveis locais A variable declared inside a function is only visible inside that function.