Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
// Import the factorial function from the factorial.js file
const { factorial } = require('./utils/factorial');

// The main() function calculates the factorial of 5 and logs the result to the console
const { convertToCelsius } = require('./utils/fahrenheit_to_celsius_converter');

// The main() function calculates the factorial of 5 & converts the fahrenheit temp of 50 to celsius, and logs both results to the console
async function main () {
const result = factorial(5); // Call the factorial function with the value of 5
console.log('factorial of 5 is', result); // Log the result to the console

const fahrenheitTemp = 50; // Fahrenheit temp to convert to Celsius
const celsiusTemp = convertToCelsius(fahrenheitTemp); // Convered temperature
console.log('the Celsius temperature is:', celsiusTemp); // log to console
}

main(); // Call the main function to calculate the factorial of 5
main(); // Call the main function to calculate the factorial of 5 & convert the fahrenheit temp of 50
25 changes: 25 additions & 0 deletions src/utils/fahrenheit_to_celsius_converter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Author: Kaitlyn Kelly
* Date: 6/3/2026
* File: fahrenheit_to_celsius_converter.js
* Description: This script converts a fahrenheit temp to a celsius temp
*/
'use strict';

// function to convert a fahrenheit temp to equal temp in celsius
function convertToCelsius(n) {

// if n is not a number, throw error and return
if (typeof n !== 'number' || Number.isNaN(n)) {
throw new Error('Input must be a valid number');
}

// formula to convert n to a celsius temp & store in celsiusTemp variable
const celsiusTemp = (n - 32) * (5/9);

// round converted celsius temp to two decimal places & return value
return Math.round(celsiusTemp * 100) / 100;
}

// Export the function for use in other scripts
module.exports = { convertToCelsius };
30 changes: 30 additions & 0 deletions test/utils/fahrenheit_to_celsius_converter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Author: Kaitlyn Kelly
* Date: 6/3/2026
* File: fahrenheit_to_celsius_converter.spec.js
* Description: This script tests the convertToCelsius function
*/
'use strict';

// import the convertToCelsius functon from its file
const { convertToCelsius } = require ('../../src/utils/fahrenheit_to_celsius_converter');

describe('fahrenheit_to_celsius_converter.js', () => {

// test that the function correctly converts a temperature to celsius
it('should convert a fahrenheit temperature to its celsius equivalent', () => {
const result = convertToCelsius(100);
expect(result).toBe(37.78);
});

// test that the function converts a negative number
it('should convert a negative temperature to its celsius equivalent', () => {
const result = convertToCelsius(-5);
expect(result).toBe(-20.56);
});

// test that the function throws an error when a non-number is supplied
it('should throw an error when a non-number is supplied as the input', () => {
expect(() => convertToCelsius("ten")).toThrow('Input must be a valid number');
});
});