Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add app.js and test.js #77

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
28 changes: 28 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// We declare the function with the exact name "fromEuroToDollar"
const fromEuroToDollar = function(valueInEuro) {
// Convert the given valueInEuro to dollars
let valueInDollar = valueInEuro * 1.07;
// return the dollar value
return valueInDollar;
}

// One euro is:
let oneEuroIs = {
"JPY": 156.5, // japan yen
"USD": 1.07, // us dollar
"GBP": 0.87, // british pound
}

const fromDollarToYen = function(valueInDollar){
let valueInYen = (valueInDollar / oneEuroIs.USD) * oneEuroIs.JPY;
return valueInYen;
}

const fromYentoPound = function(valueInYen){
let valueInEuro = valueInYen / oneEuroIs.JPY;
let valueInPound = valueInEuro * oneEuroIs.GBP;
return valueInPound;
}

// We include fromEuroToDollar here as well because it needs to be exported
module.exports = { fromEuroToDollar, fromDollarToYen, fromYentoPound }
41 changes: 41 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
test("One euro should be 1.07 dollars", function() {
// Import the function from app.js
const { fromEuroToDollar } = require('./app.js');

// Use the function like its supposed to be used
const dollars = fromEuroToDollar(3.5);

// If 1 euro is 1.07 dollars, then 3.5 euros should be (3.5 * 1.07)
const expected = 3.5 * 1.07;

// This is the comparison for the unit test
expect(fromEuroToDollar(3.5)).toBe(3.745); // 1 euro is 1.07 dollars, then 3.5 euros should be = (3.5 * 1.07)
})

test("Yen to pound", function() {
// Import the function from app.js
const { fromYentoPound } = require('./app.js');

// Use the function like its supposed to be used
const dollars = fromYentoPound(3.5);

// If 156.5 Yen is 1 Euro, then 3.5 euros should be (3.5 / 156.5) * 0.87
const expected = (3.5 / 156.5) * 0.87;

// This is the comparison for the unit test
expect(dollars).toBe(expected);
})

test("Dollar to Yen", function() {
// Import the function from app.js
const { fromDollarToYen } = require('./app.js');

// Use the function like its supposed to be used
const dollars = fromDollarToYen(3.5);

// If 1 euro is 156.5 Yen, then 3.5 euros should be (3.5 / 1.07) * 156.5
const expected = (3.5 / 1.07) * 156.5;

// This is the comparison for the unit test
expect(dollars).toBe(expected);
})