Skip to content

Commit 7cf4aa1

Browse files
author
Adria Vieira
committed
Task calculator translated
1 parent 1570319 commit 7cf4aa1

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

2-
- Please note how methods are stored. They are simply added to the internal object.
3-
- All tests and numeric conversions are done in the `calculate` method. In future it may be extended to support more complex expressions.
2+
- Por favor, note como os métodos são armazenados. Eles são simplesmente adicionados no objeto interno.
3+
- Todos os testes e conversões numéricas são feitas no método `calculate`. No futuro, pode ser extendida para suportar mais expressões complexas.

1-js/05-data-types/05-array-methods/6-calculator-extendable/task.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,38 @@ importance: 5
22

33
---
44

5-
# Create an extendable calculator
5+
# Crie uma calculadora extensível
66

7-
Create a constructor function `Calculator` that creates "extendable" calculator objects.
7+
Construa uma função construtora `Calculator` que crie objetos de calculadora "extensível".
88

9-
The task consists of two parts.
9+
A atividade consiste de duas partes.
1010

11-
1. First, implement the method `calculate(str)` that takes a string like `"1 + 2"` in the format "NUMBER operator NUMBER" (space-delimited) and returns the result. Should understand plus `+` and minus `-`.
11+
1. Primeiro, implemente o método `calculate(str)` que pegue uma string como `"1 + 2"` e a deixe no formato "NÚMERO operador NÚMERO" (delimitada por espaços) e retorne o resultado. Deve entender os operadores mais `+` e menos `-`.
1212

13-
Usage example:
13+
Exemplo:
1414

1515
```js
1616
let calc = new Calculator;
1717

1818
alert( calc.calculate("3 + 7") ); // 10
1919
```
20-
2. Then add the method `addMethod(name, func)` that teaches the calculator a new operation. It takes the operator `name` and the two-argument function `func(a,b)` that implements it.
20+
2. Então, adicione o método `addMethod(name, func)` que ensina a calculadora uma nova operação. O método pega o operador `name` e a função que recebe dois argumentos `func(a,b)` para implementar a nova operação.
2121

22-
For instance, let's add the multiplication `*`, division `/` and power `**`:
22+
Por exemplo, vamos adicionar multiplicação `*`, divisão `/` e potenciação `**`:
2323

2424
```js
25+
let multCalc = new Calculator;
26+
let divCalc = new Calculator;
2527
let powerCalc = new Calculator;
26-
powerCalc.addMethod("*", (a, b) => a * b);
27-
powerCalc.addMethod("/", (a, b) => a / b);
28+
29+
multCalc.addMethod("*", (a, b) => a * b);
30+
divCalc.addMethod("/", (a, b) => a / b);
2831
powerCalc.addMethod("**", (a, b) => a ** b);
2932
3033
let result = powerCalc.calculate("2 ** 3");
3134
alert( result ); // 8
3235
```
3336

34-
- No brackets or complex expressions in this task.
35-
- The numbers and the operator are delimited with exactly one space.
36-
- There may be error handling if you'd like to add it.
37+
- Sem colchetes ou expressões complexas neste exercício.
38+
- Os números e o operador são separados por, exatamente, um espaço.
39+
- Pode haver mensagem de erro se você desejar adicionar.

0 commit comments

Comments
 (0)