-
Notifications
You must be signed in to change notification settings - Fork 37
Atividade de casa Jacira Sousa #19
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
Open
guacirita
wants to merge
1
commit into
reprograma:master
Choose a base branch
from
guacirita:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| 1. Adicione uma função `quantasChaves()` a **todos** os objetos, que retorna quantas chaves aquele objeto possui. | ||
|
|
||
|
|
||
| function quantasChaves() { | ||
| return Object.keys(this).length | ||
| } | ||
|
|
||
| // não é boa prática mudar assim o objeto | ||
| // atrela a funcao feita para estar disponivel em todos os objetos | ||
|
|
||
| Object.prototype.quantasChaves() = quantasChaves | ||
|
|
||
| nina.quantasChaves() | ||
|
|
||
| Object.keys(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 = [] | ||
|
|
||
| } | ||
| } | ||
|
|
||
| let jambo = new Gato("Jambo", 35, "preta", true, "viralata"); | ||
|
|
||
| // caso tenha criado já a classe adiciona assim | ||
| Cachorro.prototype.latir = () => console.log("au au au") | ||
|
|
||
| 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. | ||
|
|
||
|
|
||
| class Gato{} | ||
| class Cachorro{} | ||
| class Cobra{} | ||
| class Papagaio{} | ||
| class Coelho{} | ||
|
|
||
| function Brincar(animal){ | ||
| if(animal instanceof Gato){ | ||
| return console.log("Use uma caixa") | ||
| }else if(animal instanceof Cachorro){ | ||
| return console.log("Use uma bola") | ||
| }else if(animal instanceof Cobra){ | ||
| return console.log("vc não deve brincar com ela") | ||
| }else if(animal instanceof Papagaio){ | ||
| return console.log("vc deve conversar com ele") | ||
| }else if(animal instanceof Coelho){ | ||
| return console.log("vc não deve pular com ele") | ||
| }else { | ||
| return console.log("Melhor não brincar") | ||
| } | ||
| } | ||
|
|
||
| let nina = new Gato() | ||
|
|
||
| let bug = new Cachorro() | ||
|
|
||
| let louro = new Papagaio() | ||
|
|
||
| let ligeirinho = new Hamster() | ||
|
|
||
| let nazare = new Cobra() | ||
|
|
||
| brincar(nina) | ||
|
|
||
| brincar(louro) | ||
|
|
||
| brincar(louro) | ||
| Imite ele | ||
|
|
||
| brincar(nina) | ||
| Use uma cordinha | ||
|
|
||
| // declarado assim ele não reconhece | ||
| brincar(Papagaio) | ||
| melhor não brincar.. | ||
|
|
||
| brincar(Cobra) | ||
| melhor não brincar... | ||
|
|
||
| brincar(nazare) | ||
| melhor não brincar... |
File renamed without changes.
209 changes: 209 additions & 0 deletions
209
Atividades-jacira-sousa/Em casa jacira sousa/clinicaVeterinaria.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
|
|
||
|
|
||
| class Animais { | ||
| constructor(nome, idade, cor){ | ||
| this.nome = nome | ||
| this.idade = idade | ||
| this.cor = cor | ||
| this.consultas = []; | ||
| } | ||
|
|
||
| consultar() { | ||
| this.consultas.push(new Date()) | ||
| } | ||
|
|
||
|
|
||
| brincar() { | ||
| return (`${this.nome} está brincando`) | ||
| } | ||
|
|
||
| acariciar() { | ||
| console.log("Que coisa mais linda...") | ||
| } | ||
|
|
||
| alimentar(comida) { | ||
| console.log(`${this.nome} comeu ${comida}`); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| class Domestico extends Animais{ | ||
| constructor(nome, idade, cor){ | ||
| super(nome, idade, cor) | ||
| this.vacinas = []; | ||
| } | ||
| vacinar(vacina) { | ||
| this.vacinas.push(vacina) | ||
| this.consultar(); | ||
| } | ||
|
|
||
| castrar() { | ||
| if(this.castrado != true){ | ||
| this.castrado = true | ||
| console.log(`${this.nome} agora é castrado!`); | ||
| this.consultar(); | ||
| }else if(this.castrado === true){ | ||
| console.log(`${this.nome} já consta como castrado!`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| class Gato extends Domestico { | ||
| constructor(nome, idade, cor, comidaFavorita){ | ||
| super(nome, idade, cor) | ||
| this.castrado = false | ||
| this.externo = false | ||
| this.social = false | ||
| this.comidaFavorita = comidaFavorita | ||
| } | ||
|
|
||
| miar() { | ||
| console.log("Miau, Miau") | ||
| } | ||
|
|
||
| acariciar(){ | ||
| super.acariciar() | ||
| if(this.social === true){ | ||
| return console.log("ron ron ron") | ||
| }else if(this.social === false){ | ||
| return console.log("sil sil sil") | ||
| } | ||
| } | ||
|
|
||
| alimentar(comida){ | ||
| super.alimentar(comida) | ||
| if(comida === this.comidaFavorita){ | ||
| return this.social = true; | ||
| } else if(comida != this.comidaFavorita){ | ||
| return this.social = false; | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| let tapioca = new Gato("Tapioca", 2, "branca", "peixe") | ||
|
|
||
| let gengibre = new Gato("Gengibre", 3, "laranja", "frango") | ||
|
|
||
| let shoyo = new Gato("Shoyo", 2, "preto", "peixe") | ||
|
|
||
|
|
||
|
|
||
| class Cachorro extends Domestico { | ||
| #segredo | ||
|
|
||
| constructor(nome, idade, cor, raca, ferido, segredo){ | ||
| super(nome, idade, cor) | ||
| this.castrado = false | ||
| this.raca = raca | ||
| this.ferido = ferido | ||
| this.#segredo = segredo | ||
| } | ||
|
|
||
| latir(){ | ||
| console.log("Au Au Au"); | ||
| } | ||
|
|
||
| brincar(){ | ||
| super.brincar() | ||
| if(this.ferido != false){ | ||
| console.log(`${this.nome} agora confia em você!`) | ||
| }else { | ||
| return (`${this.nome} está brincando`) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| contar() { | ||
| if(this.ferido) { | ||
| let contando = `...${this.#segredo}` | ||
|
|
||
| console.log("Preciso contar uma coisa..."); | ||
| console.log(contando); | ||
| }else{ | ||
| console.log("Não tenho nada para contar"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| let caquinho = new Cachorro("Caquinho", 10, "preta", "Buldog", false, false) | ||
| let mutley = new Cachorro("Mutley", 5, "malhada", "Viralata", true, "estou com a pata ferida!") | ||
|
|
||
|
|
||
| class Exotico extends Animais{ | ||
| constructor(nome, idade, cor) { | ||
| super(nome, idade, cor) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| class Hamster extends Exotico { | ||
| constructor(nome, idade, cor, tipo){ | ||
| super(nome, idade, cor) | ||
| this.tipo = tipo | ||
| } | ||
|
|
||
| consultar(){ | ||
| super.brincar() | ||
| console.log(`${this.nome} já pode ser consultado`) | ||
| super.consultar() | ||
| } | ||
| } | ||
|
|
||
| let ligeirinho = new Hamster("Ligeirinho", 1, "branca", "sírio") | ||
|
|
||
| let larica = new Hamster("Larica", 2, "branca", "sírio") | ||
|
|
||
|
|
||
| class Papagaio extends Exotico{ | ||
| constructor(nome, idade, cor){ | ||
| super(nome, idade, cor) | ||
| } | ||
|
|
||
| brincar(){ | ||
| super.brincar() | ||
| console.log("De novo, de novo...") | ||
| } | ||
|
|
||
| alimentar(comida){ | ||
| super.alimentar(comida) | ||
| console.log("Gostosa, gostosa...") | ||
| } | ||
| } | ||
|
|
||
| let cagoeta = new Papagaio("Cagoeta", 2, "verde") | ||
|
|
||
| let dedoduro = new Papagaio("Dedoduro", 2, "verde") | ||
|
|
||
|
|
||
|
|
||
| // tentei de várias formas, mas não retorna os animais que precisam responder, | ||
| // fica a última versão, pois já apaguei todas as outras, frustrei. | ||
|
|
||
|
|
||
| const animaisChamados = [ | ||
|
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. também não consegui chamar os animais |
||
| tapioca, gengibre, shoyo, | ||
| caquinho, mutley, | ||
| ligeirinho, larica, | ||
| cagoeta, dedoduro | ||
| ]; | ||
|
|
||
|
|
||
|
|
||
| function buscar(animaisChamados){ | ||
| const chamadaRespondida = animaisChamados.filter(animal); | ||
| if((animal instanceof Domestico) && (this.social != false)){ | ||
| chamadaRespondida.push(this.nome); | ||
| } | ||
| return console.log(chamadaRespondida) | ||
| } | ||
|
|
||
|
|
||
|
|
||
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
boa ideia usar template string