Skip to content
Closed
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
2 changes: 0 additions & 2 deletions 1-js/04-object-basics/01-object/2-hello-object/solution.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@


```js
let user = {};
user.name = "John";
user.surname = "Smith";
user.name = "Pete";
delete user.name;
```

14 changes: 7 additions & 7 deletions 1-js/04-object-basics/01-object/2-hello-object/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 5

---

# Hello, object
# Olá, objeto

Write the code, one line for each action:
Escreva o código, uma ação por linha:

1. Create an empty object `user`.
2. Add the property `name` with the value `John`.
3. Add the property `surname` with the value `Smith`.
4. Change the value of the `name` to `Pete`.
5. Remove the property `name` from the object.
1. Crie um objeto vazio (*empty object*) `user`.
2. Adicione a propriedade `name` com o valor `John`.
3. Adicione a propriedade `surname` com o valor `Smith`.
4. Altere o valor de `name` para `Pete`.
5. Remova a propriedade `name` do objeto.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function isEmpty(obj) {
for (let key in obj) {
// if the loop has started, there is a property
// se o laço começou, existe uma propriedade
return false;
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions 1-js/04-object-basics/01-object/3-is-empty/_js.view/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
describe("isEmpty", function() {
it("returns true for an empty object", function() {
it("retorna verdadeiro para um objeto vazio", function() {
assert.isTrue(isEmpty({}));
});

it("returns false if a property exists", function() {
it("retorna falso se uma propriedade existir", function() {
assert.isFalse(isEmpty({
anything: false
}));
Expand Down
2 changes: 1 addition & 1 deletion 1-js/04-object-basics/01-object/3-is-empty/solution.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Just loop over the object and `return false` immediately if there's at least one property.
Simplemente, percorra (*loop over*) o objeto e imediatamente `return false` se pelo menos houver uma propriedade.
13 changes: 6 additions & 7 deletions 1-js/04-object-basics/01-object/3-is-empty/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ importance: 5

---

# Check for emptiness
# Verifique por vazio (*emptiness*)

Write the function `isEmpty(obj)` which returns `true` if the object has no properties, `false` otherwise.

Should work like that:
Escreva a função `isEmpty(obj)`, que retorna `true` se o objeto não tiver propriedades, e `false` caso contrário.

Deve assim funcionar:
```js
let schedule = {};

alert( isEmpty(schedule) ); // true
alert( isEmpty(schedule) ); // verdadeiro

schedule["8:30"] = "get up";
schedule["8:30"] = "levante-se";

alert( isEmpty(schedule) ); // false
alert( isEmpty(schedule) ); // falso
```

10 changes: 5 additions & 5 deletions 1-js/04-object-basics/01-object/4-const-object/solution.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Sure, it works, no problem.
Com certeza, funciona, sem problemas.

The `const` only protects the variable itself from changing.
A `const` apenas protege a própria variável contra alterações.

In other words, `user` stores a reference to the object. And it can't be changed. But the content of the object can.
Por outras palavras, `user` armazena uma referência ao objeto. E não pode ser alterada. Mas, o conteúdo do objeto pode.

```js run
const user = {
name: "John"
};

*!*
// works
// funciona
user.name = "Pete";
*/!*

// error
// erro
user = 123;
```
6 changes: 3 additions & 3 deletions 1-js/04-object-basics/01-object/4-const-object/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ importance: 5

---

# Constant objects?
# Objetos constantes?

Is it possible to change an object declared with `const`? What do you think?
É possível alterar um objeto declarado com `const`? O que acha?

```js
const user = {
name: "John"
};

*!*
// does it work?
// isto funciona?
user.name = "Pete";
*/!*
```
1 change: 0 additions & 1 deletion 1-js/04-object-basics/01-object/5-sum-object/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ for (let key in salaries) {

alert(sum); // 390
```

8 changes: 4 additions & 4 deletions 1-js/04-object-basics/01-object/5-sum-object/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 5

---

# Sum object properties
# Soma das propriedades de um objeto

We have an object storing salaries of our team:
Temos um objeto armazenando salários da nossa equipa:

```js
let salaries = {
Expand All @@ -14,6 +14,6 @@ let salaries = {
}
```

Write the code to sum all salaries and store in the variable `sum`. Should be `390` in the example above.
Escreva o código para somar todos os salários e armazenar na variável `sum`. Para o exemplo acima, deverá ser `390`.

If `salaries` is empty, then the result must be `0`.
Se `salaries` for vazio, então o resultado deve ser `0`.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
let menu = {
width: 200,
height: 300,
title: "My menu"
title: "O meu menu"
};


function multiplyNumeric(obj) {

/* your code */
/* o seu código */

}

multiplyNumeric(menu);

alert( "menu width=" + menu.width + " height=" + menu.height + " title=" + menu.title );
alert( "largura do menu=" + menu.width + " altura=" + menu.height + " título=" + menu.title );

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
describe("multiplyNumeric", function() {
it("multiplies all numeric properties by 2", function() {
it("multiplica todas as propriedades numéricas por 2", function() {
let menu = {
width: 200,
height: 300,
title: "My menu"
title: "O meu menu"
};
let result = multiplyNumeric(menu);
assert.equal(menu.width, 400);
assert.equal(menu.height, 600);
assert.equal(menu.title, "My menu");
assert.equal(menu.title, "O meu menu");
});

it("returns nothing", function() {
it("não retorna nada", function() {
assert.isUndefined( multiplyNumeric({}) );
});

Expand Down
20 changes: 9 additions & 11 deletions 1-js/04-object-basics/01-object/8-multiply-numeric/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,30 @@ importance: 3

---

# Multiply numeric properties by 2
# Multiplica as propriedades numéricas por 2

Create a function `multiplyNumeric(obj)` that multiplies all numeric properties of `obj` by `2`.
Crie uma função `multiplyNumeric(obj)` que multiplica todas as proriedades numéricas de `obj` por `2`.

For instance:
Por exemplo:

```js
// before the call
// antes da chamada
let menu = {
width: 200,
height: 300,
title: "My menu"
title: "O meu menu"
};

multiplyNumeric(menu);

// after the call
// depois da chamada
menu = {
width: 400,
height: 600,
title: "My menu"
title: "O meu menu"
};
```

Please note that `multiplyNumeric` does not need to return anything. It should modify the object in-place.

P.S. Use `typeof` to check for a number here.

Por favor, note que `multiplyNumeric` não precisa de retornar nada. Deve modificar o próprio objecto.

P.S. Use `typeof` para verificar por um número aqui.
Loading