-
Notifications
You must be signed in to change notification settings - Fork 37
Prototype II - Roberta Amaro #17
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| 1. Adicione uma função `quantasChaves()` a **todos** os objetos, que retorna quantas chaves aquele objeto possui. | ||
|
|
||
| function quantasChaves() { | ||
| return this.keys().lenght | ||
| } | ||
|
|
||
| Object.prototype.quantasChaves = quantasChaves | ||
|
|
||
| 2. A partir do nosso objeto de `Cachorro` da semana passada, escreva um novo construtor que utilize classes. Lembre-se que cachorros precisam `latir()`. | ||
|
|
||
| ``` | ||
| { | ||
| nome: "Zeus", | ||
| idade: 42, //em meses | ||
| cor: "preto", | ||
| castrado: false, | ||
| raça: "labrador", | ||
| historico: [] | ||
| } | ||
| ``` | ||
|
|
||
| 3. Escreva uma função `brincar`, que te dá instruções sobre como brincar com cada espécie de animal. A função deve receber um animal como parâmetro (gato, cachorro, cobra, papagaio e pelo menos mais um outro animal de sua escolha) e, baseado na sua espécie, retornar qual brinquedo você deveria usar com ele. Ou, se for uma cobra, te dizer para não brincar com ela. | ||
|
|
||
| let zeus = New Animal("Zeus", 42, "preto", false, "labrador", []) { | ||
| this.nome = nome, | ||
| this.idade = idade, | ||
| this. cor = cor, | ||
| this.castrado = castrado, | ||
| this.raca = raca, | ||
| this.historico = New historico | ||
| } | ||
|
|
||
| zeus.latir = () => { | ||
| console.log(" au au") | ||
| } | ||
|
|
||
| Animal.prototype.brincar(cachorro) = "bola" | ||
| Animal.prototype.brincar(gato) = "varinha" | ||
| Animal.prototype.brincar(cobra) = false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| function quantasChaves(value) { | ||
| this.value = value; | ||
| return Object.keys(value); | ||
| } | ||
|
|
||
| // quantasChaves(nina); | ||
|
|
||
| // 2. A partir do nosso objeto de Cachorro da semana passada, escreva um novo construtor que utilize classes. Lembre-se que cachorros precisam latir(). | ||
|
|
||
| // { | ||
| // nome: "Zeus", | ||
| // idade: 42, //em meses | ||
| // cor: "preto", | ||
| // castrado: false, | ||
| // raça: "labrador", | ||
| // historico: [] | ||
| // } | ||
|
|
||
| class Cachorro { | ||
| constructor(nome, idade, cor, castrado, raca) { | ||
| this.nome = nome; | ||
| this.idade = idade; | ||
| this.cor = cor; | ||
| this.castrado = castrado; | ||
| this.raca = raca; | ||
|
|
||
| //this.historico = new historico(); | ||
| } | ||
| latir() { | ||
| console.log("au au"); | ||
| } | ||
| } | ||
|
|
||
| let apollo = new Cachorro("Apollo", 86, "branco", true, "vira-lata"); | ||
| apollo.latir(); | ||
|
|
||
| Cachorro.prototype.brincar = () => { | ||
| console.log("ypieee"); | ||
| }; | ||
|
|
||
| /* console.log(apollo); */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| class AnimalDomestico { | ||
| constructor(nome, idade, cor, castrado) { | ||
| this.nome = nome; | ||
| this.idade = idade; | ||
| this.cor = cor; | ||
| this.consultas = []; | ||
| this.vacinas = []; | ||
| this.castrado = castrado; | ||
| } | ||
| } | ||
|
|
||
| class Gato extends AnimalDomestico { | ||
| constructor(nome, idade, cor, castrado, externo, social) { | ||
| super(nome, idade, cor, castrado); | ||
| this.externo = externo; | ||
| this.social = social; | ||
| this.consultas = []; | ||
| this.vacinas = []; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eu acho que não precisaria repetir o "this.consultas" e o "this.vacinas", porque essas informações já estão dentro de "AnimalDomestico". Não citei novamente no meu e deu certo, mas se tá certo ou não, aí não sei dizer kkkk |
||
| miar() { | ||
| console.log("miau miau"); | ||
| } | ||
| brincar() { | ||
| console.log(`${this.nome} use uma varinha`); | ||
| } | ||
| acariciar() { | ||
| if (this.social == true) { | ||
| console.log("ron ron ron"); | ||
| } else { | ||
| console.log("schiiii"); | ||
| } | ||
| } | ||
| vacinar(vacina) { | ||
| this.vacinas.push(vacina); | ||
| this.consultas.unshift(new Date()); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. O seu tá incluindo a vacina no campo de consulta, mas acho que seria ideal definir uma data, porque o "new Date" tá retornando a data de hoje. Nesse caso, teria que colocar vacina e data como argumentos. |
||
|
|
||
| castrar() { | ||
| if (this.castrado == true) { | ||
| console.log(` ${this.nome}, já está castrado.`); | ||
| } else { | ||
| console.log(`${this.nome}, foi castrado`); | ||
| this.consultas.unshift(new Date()); | ||
| return (this.castrado = true); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fiz muito parecido todos esses!! Uma coisa diferente é que não usei unshift (nem sei para o que serve, na verdade kkk) e quando tentei usar "new Date()" não deu certo no meu 😢 |
||
| } | ||
|
|
||
| alimentar() { | ||
| if (this.social == false) { | ||
| console.log(`${this.nome} recebe um delicioso peixe!`); | ||
| return this.social == true; | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fiz de uma forma diferente! Coloquei, para quando comer frango, sachê ou peixe, o gato se tornar sociável. Vou te mostrar:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obrigada pela sugestão! |
||
| } | ||
|
|
||
| Gato.prototype.especie = "doméstico"; | ||
|
|
||
| nina = new Gato("Nina", 1.5, "frajola", true, false, false); | ||
|
|
||
| class Cachorro extends AnimalDomestico { | ||
| #ferido; | ||
| constructor(nome, idade, cor, castrado, raca, ferido) { | ||
| super(nome, idade, cor, castrado); | ||
| this.raca = raca; | ||
| this.#ferido = ferido; | ||
| this.consultas = []; | ||
| this.vacinas = []; | ||
| } | ||
| latir() { | ||
| console.log("au au"); | ||
| } | ||
|
|
||
| acariciar() { | ||
| console.log(`${this.nome} abana o rabinho`); | ||
| } | ||
| brincar() { | ||
| if (this.#ferido == true) { | ||
| console.log(`${this.nome} está ferido e precisa de cuidados!`); | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. O meu ferido não funcionou como campo privado e fiz da mesma forma!! 😢 |
||
| castrar() { | ||
| if (this.castrado == true) { | ||
| console.log(` ${this.nome}, já está castrado.`); | ||
| } else { | ||
| console.log(`${this.nome}, foi castrado`); | ||
| this.consultas.unshift(new Date()); | ||
| return (this.castrado = true); | ||
| } | ||
| } | ||
| vacinar(vacina) { | ||
| this.vacinas.push(vacina); | ||
| this.consultas.unshift(new Date()); | ||
| } | ||
| } | ||
|
|
||
| Cachorro.prototype.especie = "doméstico"; | ||
|
|
||
| zeus = new Cachorro("zeus", 3.5, "preto", false, "labrador", true); | ||
|
|
||
| class AnimalExotico { | ||
| constructor(nome, idade, cor) { | ||
| this.nome = nome; | ||
| this.idade = idade; | ||
| this.cor = cor; | ||
| this.consultas = []; | ||
| } | ||
|
|
||
| consultar() { | ||
| this.consultas.push(new Date()); | ||
| } | ||
| } | ||
|
|
||
| class Hamster extends AnimalExotico { | ||
| constructor(nome, idade, cor, tipo) { | ||
| super(nome, idade, cor); | ||
| this.tipo = tipo; | ||
| } | ||
| acariciar() { | ||
| console.log(`${this.nome} vira uma bolinha`); | ||
| } | ||
| brincar() { | ||
| console.log(`${this.nome} se exercita na rodinha`); | ||
| } | ||
| alimentar() { | ||
| console.log(`${this.nome} come frutinhas`); | ||
| } | ||
|
|
||
| consultar() { | ||
| return this.brincar(); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No consultar, eu também tava retornando brincar, mas não tava dando certo. O que eu fiz depois foi inserir um "this.relaxado" no constructor e aí, se ele tivesse relaxado a consulta seria realizada, mas se não tivesse, mostrava que ele fugiu e pedia para brincar antes. Aí no brincar(), para fazer isso, teria que mudar o status dele para relaxado. Assim:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oi Babi! O meu consultar estava retornando o brincar certinho, vc testou e nao deu certo? De qualquer forma vou tesre e dar uma conferida e tentar seu método também |
||
| } | ||
|
|
||
| Hamster.prototype.especie = "exótico"; | ||
|
|
||
| iogurte = new Hamster("Iogurte", 1.5, "branco e laranja", "sírio"); | ||
|
|
||
| class Papagaio extends AnimalExotico { | ||
| constructor(nome, idade, cor) { | ||
| super(nome, idade, cor); | ||
| this.nome = nome; | ||
| this.idade = idade; | ||
| this.cor = cor; | ||
| } | ||
| falar() { | ||
| console.log("Que loucura jovem!"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kkkkkkkkkkkkk Adorei a fala dele! |
||
| } | ||
| brincar() { | ||
| console.log(`${this.nome} suba na minha mão`); | ||
| return this.falar(); | ||
| } | ||
| acariciar() { | ||
| console.log(`Acaricia o peito de ${this.nome}`); | ||
| } | ||
|
|
||
| alimentar() { | ||
| console.log(`${this.nome} come frutinhas`); | ||
| return this.falar(); | ||
| } | ||
| } | ||
|
|
||
| Papagaio.prototype.especie = "exótico"; | ||
|
|
||
| jose = new Papagaio("José", 13, "verde"); | ||
|
|
||
| //Não consegui até o meu momento fazer o item 5 e fazer retornar a consulta quando adicionada a vacina. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A função chamar eu também não consegui fazer! Tamo junto! hahaha |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Prototype 2</title> | ||
| </head> | ||
| <body> | ||
| <script src="./exercicio.js"></script> | ||
| </body> | ||
| </html> |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uma outra forma de fazer também seria criando uma classe "Animal" que daria para incluir nome, idade, cor e consultas, porque todos eles precisam dessas informações (foi assim que eu fiz hehehe).
Nesse caso, os animais domésticos, o hamster e o papagaio pegariam as informações de "animal". E depois, o cachorro e o gato pegariam as informações dos animais domésticos.
Só foi uma outra forma de pensar mesmo!!