|
1 |
| -# Average Temperature Calculation Lab |
2 |
| - |
3 |
| -## Overview: |
4 |
| -This lab focuses on calculating the average temperature in the city of Rome over a 30-day period. Temperature data is provided for each day, with some temperatures in Celsius and some in Fahrenheit. The goal is to calculate the average temperature using only basic expressions, operators, and variable assignments in JavaScript. |
5 |
| - |
6 |
| -### Mocha Tests: |
7 |
| - |
8 |
| -- When we want to run an experiment, we need to develop a hypothesis and we need to test it. In programming, we run tests to verify that programs behave the way |
9 |
| -we think they do. Tests help us identify bugs and judge how healthy our |
10 |
| -applications are. We use tests to describe the program's behavior, just as you would in a |
11 |
| -professional coding environment, and we also use them as teaching tools. You are |
12 |
| -in charge of getting the tests to pass. |
13 |
| -- Mocha tests have been provided to ensure the accuracy of temperature conversions and the correctness of the average temperature calculation. |
14 |
| -- In your terminal, once inside the lab folder, run in order: |
15 |
| - - `npm install` to install all the packages contained in the package.json |
16 |
| - - `npm test` to execute the tests and check whether your variables match the expectations |
17 |
| - - There are a total of 8 tests checking for the accuracy of tot_temperature_in_fahrenheit, tot_temperature_in_celsius, avg_temperature_in_fahrenheit, and avg_temperature_in_celsius |
18 |
| - |
19 |
| -### Structure |
20 |
| - |
21 |
| -The structure of this lab — where its files and folders are located — looks |
22 |
| -roughly like the following: |
23 |
| - |
24 |
| -```txt |
25 |
| -├── CONTRIBUTING.md |
26 |
| -├── LICENSE.md |
27 |
| -├── README.md |
28 |
| -├── index.js |
29 |
| -├── node_modules/ |
30 |
| -├── package.json |
31 |
| -└── test |
32 |
| - └── indexTest.js |
33 |
| -``` |
34 |
| - |
35 |
| -All labs will more or less have the same structure. (And non-lab lessons, for |
36 |
| -that matter, will still have CONTRIBUTING.md, LICENSE.md, and README.md files.) |
37 |
| - |
38 |
| - |
39 |
| -### Instructions: |
40 |
| -1. **Define Temperature Data:** |
41 |
| - - Data: 32°F, 25°C, 70°F, 18°C, 80°F, 15°C, 72°F, 28°C, 68°F, 20°C, 75°F, 23°C, 82°F, 30°C, 65°F, 22°C, 77°F, 26°C, 78°F, 24°C, 73°F, 21°C, 79°F, 27°C, 71°F, 19°C, 74°F, 17°C, 76°F, 29°C |
42 |
| - - Open the index.js file. |
43 |
| - - Create variables to represent temperature data listed above for each day, considering that some temperatures are in Celsius and some in Fahrenheit. |
44 |
| - - Example: |
45 |
| - ``` |
46 |
| - day1TempF = 32 |
47 |
| - day2TempC = 25 |
48 |
| - day3TempF = 70 |
49 |
| - day4TempC = 18 |
50 |
| - // ... |
51 |
| - ``` |
52 |
| -2. **Convert Temperatures:** |
53 |
| - - Apply the conversion formulas to convert temperatures to a consistent unit (either Celsius or Fahrenheit). |
54 |
| - - Formula to pass from F to C: (tempInFahrenheit - 32) * 5 / 9 |
55 |
| - - Formula to pass from C to F: (tempInCelsius * 9 / 5) + 32 |
56 |
| - |
57 |
| -3. **Calculate Total and Average Temperature:** |
58 |
| - - Sum up all the temperatures and create two variables called exactly `tot_temperature_in_fahrenheit` and `tot_temperature_in_celsius` in which you will store the correspondent values. |
59 |
| - - Once you have the total temperature in Fahrenheit and Celsius, calculate the average temperature in Fahrenheit and Celsius. Call the variables `avg_temperature_in_fahrenheit` and `avg_temperature_in_celsius`. |
60 |
| - - It's quite important to follow the naming convention as the tests rely on it, take a look at the indexTest.js file inside the test folder. |
61 |
| - |
62 |
| -4. **Test Your Code :** |
63 |
| - - As you advance with your code, run the tests to check on your progress |
64 |
| - - Feel free to also place `console.log()` around your code to display the value of your variables. In order for you to execute your file, follow these steps: |
65 |
| - 1. Check what files and folders are currently in your directory typing `ls` in your terminal. |
66 |
| - 2. Do you see the index.js file? If not, use the command `cd` followed by the name of the folder to move into a folder or the `cd ..` command to move out of a folder until you see the index.js file. |
67 |
| - 3. Run `node index.js` to execute your js file, you should see your logs in the terminal. |
68 |
| - 4. In general, we use `node` followed by the path to the file we want to execute. If the file is in a folder, you can use `node folderName/fileName.js` to execute it. |
69 |
| -
|
70 |
| -
|
71 |
| -### Submitting Your Solution: |
72 |
| -- When you are done, submit your solution by saving your progress with git: |
73 |
| - 1. Add your changes to the staging area by executing `git add .` |
74 |
| - 2. Create a commit by executing `git commit -m "Your commit message"` |
75 |
| - 3. Push your commits to GitHub by executing `git push origin main` or `git push origin master` depending on the name of your branch (use `git branch` to check on which branch you are). |
76 |
| - 4. Go to CodeGrade and link the repository to your assignment to submit your work. |
0 commit comments