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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
194 changes: 45 additions & 149 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion 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');

// Import the rectangle area function from the rectangle.js file
const { calculateRectangleArea } = require('./utils/rectangle');

// The main() function calculates the factorial of 5 and logs the result 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 area = calculateRectangleArea(5, 10); // Call the calculateRectangleArea function
console.log('area of rectangle (5 x 10) is', area); // Log the result to the console
}

main(); // Call the main function to calculate the factorial of 5
main(); // Call the main function to calculate the factorial of 5, and also calculate the area of a 5 x 10 rectangle.
21 changes: 21 additions & 0 deletions src/utils/rectangle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Author: Ben Hilarides
* Date: 16 January 2026
* File: rectangle.spec.js
* Description: This script tests the rectangle area calculation function.
*/
'use strict';

/**
* Calculates the area of a rectangle.
* @param {number} length - The length of the rectangle
* @param {number} width - The width of the rectangle
* @returns {number} The area of the rectangle
*/
function calculateRectangleArea(length, width) {
return length * width;
}

module.exports = {
calculateRectangleArea
}
31 changes: 31 additions & 0 deletions test/utils/rectangle.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Author: Ben Hilarides
* Date: 16 January 2026
* File: rectangle.spec.js
* Description: This script tests the rectangle area calculation function.
*/
'use strict';

const { calculateRectangleArea } = require('../../src/utils/rectangle'); // Import the rectangle area function from the rectangle.js file

// The describe() function is a test suite that contains one or more tests
describe('rectangle.js', () => {

// Test for calculating area with positive integers
it('should calculate area of 5 x 10 as 50', () => {
const result = calculateRectangleArea(5, 10);
expect(result).toBe(50);
});

// Test for calculating area of a square
it('should calculate area of 5 x 5 as 25', () => {
const result = calculateRectangleArea(5, 5);
expect(result).toBe(25);
});

// Test for calculating area with decimal values
it('should calculate are of 3.5 x 2.5 as 8.75', () => {
const result = calculateRectangleArea(3.5, 2.5);
expect(result).toBe(8.75);
});
})