mirror of
https://github.com/10h30/odin-javascript-exercises.git
synced 2026-06-05 15:09:09 +09:00
Order exercise folders
Ordered the exercise folders by placing their numbers in their folder name
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
# Exercise 07 - tempConversion
|
||||
|
||||
Write two functions that convert temperatures from Fahrenheit to Celsius, and vice versa:
|
||||
```
|
||||
ftoc(32) // fahrenheit to celsius, should return 0
|
||||
|
||||
ctof(0) // celsius to fahrenheit, should return 32
|
||||
```
|
||||
|
||||
Because we are human, we want the result temperature to be rounded to one decimal place: i.e., `ftoc(100)` should return `37.8` and not `37.77777777777778`.
|
||||
|
||||
This exercise asks you to create more than one function so the `module.exports` section of the spec file looks a little different this time. Nothing to worry about, we're just packaging both functions into a single object to be exported.
|
||||
|
||||
## Hints
|
||||
- You can find the relevant formulae on [Wikipedia](https://en.wikipedia.org/wiki/Conversion_of_units_of_temperature).
|
||||
|
||||
- Try to find by yourself on the Internet how to round a number to 1 decimal place in JavaScript. If you struggle, have a look [here](https://stackoverflow.com/q/7342957/5433628).
|
||||
@@ -0,0 +1,12 @@
|
||||
const ftoc = function() {
|
||||
|
||||
};
|
||||
|
||||
const ctof = function() {
|
||||
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
ftoc,
|
||||
ctof
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
const {ftoc, ctof} = require('./tempConversion')
|
||||
|
||||
describe('ftoc', () => {
|
||||
test('works', () => {
|
||||
expect(ftoc(32)).toEqual(0);
|
||||
});
|
||||
test.skip('rounds to 1 decimal', () => {
|
||||
expect(ftoc(100)).toEqual(37.8);
|
||||
});
|
||||
test.skip('works with negatives', () => {
|
||||
expect(ftoc(-100)).toEqual(-73.3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ctof', () => {
|
||||
test.skip('works', () => {
|
||||
expect(ctof(0)).toEqual(32);
|
||||
});
|
||||
test.skip('rounds to 1 decimal', () => {
|
||||
expect(ctof(73.2)).toEqual(163.8);
|
||||
});
|
||||
test.skip('works with negatives', () => {
|
||||
expect(ctof(-10)).toEqual(14);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user