隆Te damos la bienvenida a este reto!

1

隆Bienvenido al mundo de JavaScript!

D铆a 1

2

Variables, funciones y sintaxis b谩sica

3

Tipos de datos

4

Playground - Retorna el tipo

5

Tipos de datos - pt 2

D铆a 2

6

Operadores

7

Hoisting y coerci贸n

8

Playground - Calcula la propina

9

Alcance de las variables

D铆a 3

10

Condicionales

11

Playground - Calcula a帽os bisiestos

12

Switch

13

Playground - Obten informaci贸n de mascotas seg煤n su tipo

14

Ciclos

15

Playground - Dibuja un triangulo

D铆a 4

16

Arrays

17

Playground - Encuentra al michi mas famoso

18

Objetos

19

Playground - Obten el promedio de los estudiantes

D铆a 5 - Checkpoint

20

Playground - encuentra el palindromo m谩s grande

D铆a 6

21

Reasignaci贸n y redeclaraci贸n

22

Modo estricto

D铆a 7

23

Debugging y manejo de errores

24

Programaci贸n funcional

Quiz: D铆a 7

D铆a 8

25

Closures

26

Playground - Crea una calculadora con closures

27

Higher order functions

28

Playground - Crea tu propio m茅todo map

D铆a 9

29

ECMAScript

30

TC39

Quiz: D铆a 9

D铆a 10 - Checkpoint

31

ES6

32

ES7

33

Playground - Task planner

D铆a 11

34

Asincronismo

35

Playground - Promesas

36

Manejando el asincronismo

37

Playground - Resuelve el callback hell usando promesas

38

Playground - Resuelve el callback hell usando async/await

D铆a 12

39

Arrays a profundidad

40

M茅todos de arrays: Every, Find y findIndex

41

Playground - V谩lida el formulario

D铆a 13

42

M茅todos de arrays: Includes, Join y concat

43

Playground - agrupa los productos

44

M茅todos de arrays: Flat y FlatMap

45

Playground - Encuentra la ubicaci贸n del valor buscado

D铆a 14

46

Mutable functions

47

Playground - Modifica una lista de compras

48

M茅todos de arrays: sort

49

Playground - Ordena los productos

D铆a 15 - Checkpoint

50

Playground - Sistema de reservaciones de un hotel

D铆a 16

51

Programaci贸n orientada a objetos en JavaScript

52

Objetos literales

53

Playground - Congela el objeto recursivamente

D铆a 17

54

Prototipos en JavaScript

55

Playground - Modifica el prototype de los arrays

56

Playground - Crea un auto usando clases

D铆a 18

57

Abstracci贸n en JavaScript

58

Playground - Sistema de carrito de compras

59

Encapsulamiento en JavaScript

60

Playground - Encapsula datos de los usuarios

D铆a 19

61

Herencia en JavaScript

62

Playground - Jerarqu铆a de animales

63

Polimorfismo en JavaScript

64

Playground - Sistema de pagos

D铆a 20 - Checkpoint

65

Playground - Agenda de vuelos

D铆a 21

66

Patrones de dise帽o

67

Sinlgeton y Factory pattern en JavaScript

68

Playground - Implementa singleton en un chat

D铆a 22

69

Adapter y Decorator pattern en JavaScript

70

Playground - Personaliza productos de una tienda

71

Builder y Protype pattern en JavaScript

72

Playground - Mejora el c贸digo usando builder pattern

D铆a 23

73

Facade y proxy pattern en JavaScript

74

Playground - Proxy en servicio de mensajer铆a

75

Chain of responsability y Observer pattern en JavaScript

76

Playground - Implementaci贸n de Observador en Newsletter

D铆a 24 - Checkpoint

77

Playground - Crea un task manager con patrones de dise帽o

D铆a 25

78

Estructuras de datos en JavaScript

79

Playground - Crea tu propia implementaci贸n de un array

80

Hash tables en JavaScript

81

Playground - Implementaci贸n de una HashTable para Contactos

D铆a 26

82

Set en JavaScript

83

Playground - Remueve duplicados de una lista

84

Maps en JavaScript

85

Playground - Crea un organizador de tareas

D铆a 27

86

Singly Linked List en JavaScript

87

Playground - Agrega m茅todos a la singly linked list

88

Playground - Implementaci贸n de una singly linked list

D铆a 28

89

Stacks en JavaScript

90

Playground - Crea un stack para una playlist

D铆a 29

91

Queues en JavaScript

92

Playground - Crea una cola de emails

D铆a 30

93

隆Lo lograste!

Live Class

94

30 d铆as de JS con Juan DC

95

30 d铆as de JS con Nicobytes

96

30 d铆as de JS con GNDX

97

30 d铆as de JS con LeoCode

98

30 d铆as de JS con Teffcode

99

Sesi贸n: Cierre de los 30 d铆as de JavaScript

No tienes acceso a esta clase

隆Contin煤a aprendiendo! 脷nete y comienza a potenciar tu carrera

Aprende Ingl茅s, Programaci贸n, AI, Ciberseguridad y m谩s a precio especial.

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

1 D铆as
11 Hrs
32 Min
47 Seg

Playground - Crea un auto usando clases

56/99

Aportes 49

Preguntas 0

Ordenar por:

驴Quieres ver m谩s aportes, preguntas y respuestas de la comunidad?

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(kilometers) {

    if (this.state) {
      this.mileage  += kilometers;
    } else {
      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(km) {
    if (this.state) {
      this.mileage += km;
      return km;
    }

    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:

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');
  }
}

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

Soluci贸n al desafio JS:

馃洝锔忦煕★笍馃洝锔廍scudo anti spoilers馃洝锔忦煕★笍馃洝锔

Crea un auto usando clases

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 馃挌

.
.
.

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;
  }
}

馃洝锔忦煕★笍Escudo anti-spoilers馃洝锔忦煕★笍

Mi soluci贸n al reto:

export class Car {
  brand = ''
  model = ''
  year = ''
  mileage = ''
  state = false

  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) throw new Error("El auto est谩 apagado")
    this.mileage += kilometers
    return this.mileage
  }

}

Solucion

class Car {
    constructor(brand, model, year,) {
        this.brand = brand;
        this.model = model;
        this.year = year;
        this.mileage = 0;
        this.state = false;
    }

    turnOn() {
        console.log("Car turned on! No pun intended")
        this.state = true;
    }

    turnOff() {
        console.log("Car turned off! No pun intended");
        this.state = false;
    }

    drive(miles) {
        if (this.state === false) {
            const error = new Error("Error: Car is turned off...");
            console.log(error.message)
            return
        }
        this.mileage += miles
        return this.mileage
    }
}

Esta es mi soluci贸n

class Car {
    constructor(brand, model, year, mileage)
    {
        this._brand      = brand;
        this._model      = model;
        this._year       = year;
        this._mileage    = mileage;
        let state        =  false;
    }

    get mileage()
    {
        return this._mileage;
    }
    set mileage(newMileage)
    {
        this._mileage = newMileage;
    }


    get brand()
    {
        return this._brand;
    }

    set brand(newBrand)
    {
        this._brand = newBrand;
    }

    get model()
    {
        return this._model;
    }
    set model(newModel)
    {
        this._model = newModel;
    }

    get year()
    {
        return this._year;
    }

    set year(newYear)
    {
        this._year = newYear;
    }
    
    turnOn()
    {
       this.state = true; 
    }

    turnOff()
    {
        this.state = false; 
    }

    drive(kilometers)
    {
        if (this.state)
        {
            this.mileage += kilometers;
        }
        else
        {
            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");
    }
  }
}
export class Car {
  // Tu c贸digo aqu铆 馃憟
  constructor(brand, model, year, mileage) {
    this.brand = brand;
    this.model = model;
    this.year = year;
    this.mileage = mileage;
    this.state = false;
  }

  turnOn() {
    this.state = true;
    return this.state
  }

  turnOff() {
    this.state = false;
    return this.state;
  }

  drive(kilometers) {
    if (!this.state) {
      throw new Error("El auto est谩 apagado")
    }

    this.mileage += kilometers;
    return this.mileage;
  }
}

My solution

export class Car {
  constructor(
    _brand,
    _model,
    _year,
    _mileage,
    _state,
  ) { 
    this.brand = _brand;
    this.model = _model;
    this.year = _year;
    this.mileage = 0;
    this.state = false;
  }

  turnOn() {
    this.state = true;
  }
  turnOff() {
    this.state = false
  }
  drive(kilometers) {
    if (this.state) {
      this.mileage += kilometers;
    } else {
      throw Error("El auto est谩 apagado")
    }
  }
}

隆Hola 馃槂!

Mi soluci贸n,
Se detalla hasta abajo.猬











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 solucion
+
+
+
+
+
+
+
+
+
+

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() {
    return this.state = true;
  }

  turnOff() {
    return this.state = false;
  }

  drive(kilometers) {
    if (this.state === true) {
      this.mileage += kilometers;
      return this.mileage;
    } else {
      throw new Error("El auto est谩 apagado");
    }
  }
}

Mis solucion, pero me marcaba error solo por un acento, que raro
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

export class Car {
  // Tu c贸digo aqu铆 馃憟
  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(vel) {
    if (!this.state) 
      throw new Error('El auto est谩 apagado');
    this.mileage += vel;
  }
}

En el constructor de la clase, se definen las propiedades brand, model, year, mileage y state. El estado por defecto del auto es false, indicando que se encuentra apagado.

El m茅todo turnOn cambia el estado del auto a true, indicando que se encuentra encendido.

El m茅todo turnOff cambia el estado del auto a false, indicando que se encuentra apagado.

El m茅todo drive recibe como par谩metro los kil贸metros que se desean agregar al kilometraje del auto. Primero verifica si el auto est谩 encendido (estado igual a true). Si el auto est谩 encendido, agrega los kil贸metros al kilometraje actual. Si el auto est谩 apagado, lanza un error indicando que el auto est谩 apagado.

En el ejemplo 1, se crea un nuevo objeto toyota de la clase Auto y se llama a los m茅todos turnOn y drive para aumentar el kilometraje. Finalmente, se muestra el kilometraje actual del auto.

En el ejemplo 2, se crea un nuevo objeto toyota de la clase Auto, se llama al m茅todo turnOff para apagar el auto y luego se llama al m茅todo drive para intentar aumentar el kilometraje. Como el auto est谩 apagado, se muestra un error indicando que el auto est谩 apagado.

class Auto{
  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");
    }
  }
}

const toyota = new Auto("Toyota", "Corolla", 2020, 0);
toyota.turnOn();
toyota.drive(100);
toyota.mileage

const toyota = new Auto("Toyota", "Corolla", 2020, 0);
toyota.turnOff()
toyota.drive(100)

Aqu铆 mi soluci贸n:
.
.
.
.
.
.
.
.
.
.
.
.

class Car {
  constructor(brand, model, year, mileage) {
    this.brand = brand
    this.model = model
    this.year  = year
    this.state = false
    this.mileage = mileage
  }

  turnOn() {
    this.state = true;
  }

  turnOff() {
    this.state = false;
  }

  drive(kilometers) {
    if (this.state){
      this.mileage += kilometers;
      return this.mileage;
    } else {
      throw new Error("El auto est谩 apagado");
    }
    
  }
}

Aqu铆 dejo mi aporte鈥 馃槂

class Car {
  // Tu c贸digo aqu铆 馃憟
  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");
    }
  }
}

Aqu铆 dejo mi aporte鈥 馃槂

class Car {
  // Tu c贸digo aqu铆 馃憟
  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:

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 Error("El auto est谩 apagado");
    }
  }
}

estuvo bastante chevere y me salio de una:

  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 === true) {

      this.mileage += kilometers;
    } else {
      throw new Error("El auto est谩 apagado");
    }
  }
  
}

the sol:

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;
    console.log("thurnOn", this.state)
  }

  turnOff() {
    this.state = false;
    console.log("turnOff", this.state)
  }

  drive(kilometers) {
    if (this.state) {
      this.mileage += kilometers;
      console.log(this.mileage)
      return this.mileage;
    } else {
      console.log(this.mileage)
      throw new Error('El auto est谩 apagado')
    }
  }

}

Mi soluci贸n
.
.
.
.
.
.

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;
    }
    else {
      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;
    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:

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
  }
}

MI SOLUCION 馃挭
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

export class Car {
  constructor(brand, model, year, mileage = 0) {
    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");
  }
}

Dejo mi soluci贸n:
.
.
.
.
.
.
.
.
.
.

export class Car {
  // Tu c贸digo aqu铆 馃憟
  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(distance) {
    if (!this.state) throw new Error("El auto est谩 apagado");
    this.mileage += distance;
  }
}

MI soluci贸n:

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(kilometers){
    if(this.state){
      this.mileage=kilometers;
    }else{
      throw new Error("El auto est谩 apagado")
    }
  }
}

Soluci贸n鈥 馃槃
.
Para resolver el ejercicio, creamos el constructor pasando los par谩metros correspondientes, donde la propiedad state ser谩 falsa por defecto.
.
Creamos los m茅todos correspondientes.
.
En turnOn y turnOff cambiaremos el estado de la propiedad state.
.
En drive(kilometers) comparamos si el auto est谩 apago, si cumple lanzamos un error, sino sumamos los kilometros al kilometraje del auto.
.

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;
  }
}

Les dejo mi soluci贸n







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(kilometers) {
    if (this.state) this.mileage += kilometers
    else throw new Error("El auto est谩 apagado")
  }
}

mi soluci贸n:

class Car{
    constructor(marca, modelo, anio, tacometro){
        this.brand   = marca;
        this.model   = modelo;
        this.year    = anio;
        this.mileage = tacometro;
        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");
    }
}

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
facilito

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")
    }
  }
}

Hola, dejo mi solucion
Caminito anti spoilers
馃洿鉁
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Llegamos 馃搷

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;
        }else{
            throw new Error("El auto est谩 apagado")
        }
    }

Bueno este reto es sencillo pero debes tener aunque sea las bases de POO, les dejo abajo mi soluci贸n:

.
.
.
.
.
.
.
.
.
.
.
.
.

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(kilometers) {
    if (this.state) {
      this.mileage += 100
      return
    }
    throw Error("El auto est谩 apagado")
  }
}

Soluci贸n.

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;
    else
      throw new Error("El auto est谩 apagado");
  }
}
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(kilometers) {
    if (this.state) this.mileage += kilometers;
    else throw new Error('El auto est谩 apagado')
  }

}
undefined