Playground - Crea un auto usando clases
Clase 56 de 99 • 30 días de JavaScript
Contenido del curso
David Higuera
Carina Payleman
Daniel Romao
Pablo Pincay Alvarez
Randy Ochoa
Andrés Soret Chacin
Andres Felipe Torres
Joan Alexander Valerio Rodríguez
Harrison Steve Pinzón Neira
David Ochoa
Yerson Garza
Rubén Hernández Hernández
Pablo Perez
david alvarez
Pariksit Erikrsnan Ortiz Flores
Angel Javier Sanchez Tenjo
Alexis Corrales
Duvan Alexis Palomino Ramirez
Esteban Alzate Atehortua
Hiver Tapia
export class Car { // Tu código aquí 👈 brand; model; year; mileage; state = false; constructor(_brand, _model, _year, _mileage) { this.brand = _brand this.model = _model this.year = _year this.mileage = _mileage } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(km) { if (!this.state) throw new Error("El auto está apagado") this.mileage += km } }
export class Car { constructor( brand, model, year, mileage = 0, state = false ) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = state; } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(kilometers) { if (!this.state) { throw new Error("El auto está apagado") } else { this.mileage += kilometers; return this.mileage; } } }
Mi solucion:
export class Car { constructor(brand, model, year, mileage) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = false; } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(km) { if (this.state) { this.mileage += km; return km; } throw new Error('El auto está apagado'); } }
Mi Solucion: .
. . . . .
. . . . .
. . . . .
..
. .
export class Car { constructor(brand, model, year, mileage) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = false; } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(kilometers) { if (this.state) { this.mileage += kilometers; } else { throw new Error('El auto está apagado') } } }
Por si les ayuda. Recuerde chechar bien la ortografia en el mensaje de error que devuelven, por que eso hacia que no me marque correcto el reto
My solution 👇
constructor(brand, model, year, mileage) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = false; } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(kilometers) { if (this.state === false) { throw new Error("El auto está apagado"); } this.mileage += kilometers; }
Mi aporte
export class Car { constructor(brand, model, year, mileage, state) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = state; } turnOn() { this.state = true; return this.state; } turnOff() { this.state = false; return this.state; } drive(kilometers) { if (this.state) { this.mileage += kilometers; return; } throw new Error('El auto está apagado'); } }
Un ejercicio bastante sencillo. Continuo haciendo este comentario para futuras mejoras... Se tiene que mejorar si o si la redacción en los ejercicios. Ejemplo, nunca se menciono que era necesario retornar la data de los vehículos y para esto una de las posibles soluciones era implementar un nuevo método que devolviera estos valores.
He aprendido muchas cosas del curso, pero ese tipo de detalle puede hacer que para algunos el aprendizaje sea frustrante. Hago este comentario amistoso, porque trabajo en el área y se que en la vida de programador estos tipos de cosas pasan, pero para una persona que apenas esta conociendo de programación, encontrarse con este tipo de situaciones puede desanimarlo.
En fin :) les comparto mi solución:
Solución al desafio JS:
🛡️🛡️🛡️Escudo anti spoilers🛡️🛡️🛡️
Crea un auto usando clases
!Spoiler Shield
export class Car { // Tu código aquí 👈 constructor(brand, model, year, mileage, state = false) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = state; } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(kilometers) { if (this.state) { this.mileage += kilometers; return; } throw new Error("El auto está apagado"); } }
export class Car { constructor(brand, model, year, mileage) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = false; } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(kilometers) { if (this.state) { this.mileage += kilometers; } else { throw new Error("El auto está apagado"); } } }
Mi solución 💚 !Mcqueen . . .
export class Car { constructor(brand, model, year, mileage) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = false; } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(kilometers) { if (!this.state) throw new Error("El auto está apagado") this.mileage+=kilometers } }
export class Car { constructor(brand, model, year, mileage, state = false) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = state; } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(km) { if (this.state) { this.mileage += km; return this.mileage; } else { throw new Error("El auto está apagado"); } } }
export class Car { // Tu código aquí 👈 state = false; constructor(brand, model, year, mileage, state) { this.brand = brand this.model = model; this.mileage = mileage; this.year = year } turnOn() { this.state = true } turnOff() { this.state = false } drive(km) { if (this.state) { this.mileage += km } else throw new Error('El auto está apagado') } }
Mi aporte: | | | | | | | | | | | | |
export class Car { // Tu código aquí 👈 constructor(brand, model, year, mileage, state=false) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = state; } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(kilometers) { if (this.state !== false) { this.mileage = kilometers; } else { throw new Error('El auto está apagado'); } } }
Hola Comparto mi solución.
✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
export class Car { constructor(brand, model, year, mileage, state) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = state; } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(kilometers) { if(this.state) { this.mileage += kilometers; return; } throw new Error("El auto está apagado"); } }
export class Car { constructor(brand, model, year, mileage, state) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = state; } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(km) { if (this.state) { this.mileage += km; } else { throw new Error("El auto está apagado") } } }
Comparto mi solucion:
Mi solución: . . . . . . . . . . . . . . . . .
export class Car { constructor(brand, model, year, mileage, state) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = state; } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(kilometers) { if (this.state) { this.mileage += kilometers; } else { throw new Error("El auto está apagado") } } }
Si pude gracias..
export class Car { constructor(brand, model, year, mileage, state) { this.brand = brand; this.model = model; this.year = year; this.mileage = mileage; this.state = false; } turnOn() { this.state = true; } turnOff() { this.state = false; } drive(kilometers) { if (!this.state) throw new Error("El auto está apagado") this.mileage += kilometers; } }