Estimated Completion Time: 30-60 min.
Objective: In this lab, you will apply your knowledge of JavaScript statements to create a program that simulates an automated garden management system. You will use selection and repetition statements to control various aspects of the garden, such as watering plants, controlling garden lights, and adjusting the soil moisture level.
Scenario: You are a junior developer working for a smart home technology company. Your task is to implement features that manage and control various garden devices based on sensor data and user inputs. This involves checking conditions and iterating through device settings to maintain the garden automatically.
- Visual Studio Code
- Node.js
-
Fork and Clone the Repository:
- Fork the provided GitHub repository: https://github.com/learn-co-curriculum/phase-0-js-statements-lab.git
- Clone the forked repository to your local machine.
-
Install Dependencies:
- Run
npm installto install the necessary dependencies.
- Run
-
Initial Setup:
- Open the
gardenManagement.jsfile in your code editor. - The following variables are provided in
gardenManagement.js:const temperature = 90;const timeOfDay = "morning";let soilMoisture = 30;
- Open the
-
Run Tests:
- Run
npm testto execute the tests and see that all tests are currently failing. - As you write your code, run
npm testto check if you are passing the tests.
- Run
-
Write the Following Statements and Loops:
Watering Control:
- Use an
if-elsestatement to check thetemperature. - If the
temperatureis greater than 80, console log"Watering on". - Otherwise, console log
"Watering off".
Garden Lights Control:
- Use an
if-elsestatement to checktimeOfDay. - If
timeOfDayis"evening"or"night", console log"Lights on". - Otherwise, console log
"Lights off".
Soil Moisture Adjustment:
- Use a
whileloop to increment the value ofsoilMoistureby 5 until it reaches 40. - Console log the value of
soilMoistureat each step, and when it reaches 40, console log40.
- Use an