Recap Challenge
Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 6 of 56.
Challenge
Recap Challenge: Build a Smart Thermostat
Practice everything you learned in this chapter by creating a smart thermostat object.
Your task:
- Create a constructor function called
Thermostatthat takes aroomparameter - Inside the constructor, set these properties using
this:room(from the parameter)temperature(set to 22)isOn(set to true)
- Add these methods inside the constructor using
this:increaseTemp()- increases temperature by 1 degreedecreaseTemp()- decreases temperature by 1 degreegetStatus()- returns: "[room] thermostat: [temperature]°C"
Try it yourself
// TODO: Create a constructor function called Thermostat that takes a room parameter
// TODO: Inside the constructor, set these properties:
// - room (from the parameter)
// - temperature (set to 22)
// - isOn (set to true)
// TODO: Add a method called increaseTemp() that increases temperature by 1 degree
// TODO: Add a method called decreaseTemp() that decreases temperature by 1 degree
// TODO: Add a method called getStatus() that returns: "[room] thermostat: [temperature]°C"
// Test your code - don't modify this part
const livingRoom = new Thermostat("Living Room");
livingRoom.increaseTemp();
livingRoom.increaseTemp();
console.log(livingRoom.getStatus()); // Should print: "Living Room thermostat: 24°C"
const bedroom = new Thermostat("Bedroom");
bedroom.decreaseTemp();
bedroom.decreaseTemp();
console.log(bedroom.getStatus()); // Should print: "Bedroom thermostat: 20°C"
All lessons in Object Oriented Programming
1Objects & The this Keyword
Quick Review: ObjectsAdding Methods to ObjectsUnderstanding the this KeywordConstructor FunctionsThe new KeywordRecap Challenge7 Inheritance & The extends Key
InheritanceThe "is-a" RelationshipThe extends KeywordThe super() MethodInheriting Properties&MethodsRecap Challenge2Organizing Code
What are Modules?Exporting with exportImporting with importDefault vs. Named Exports8Organizing OOP Code
Organize Classes into Modules11Project: A Shape Renderer
Setup: Shape Class & ExportCircle Class Inheritance9Static Methods & Properties
Class-Level vs. Instance-LevelStatic PropertiesStatic Utility MethodsRecap challenge