Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Commit 6bd6418

Browse files
committed
merge
2 parents 12cf27e + 656a424 commit 6bd6418

19 files changed

+367
-289
lines changed
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
// There are syntax errors in this code - can you fix it to pass the tests?
42

53
function addNumbers(a, b, c) {
@@ -13,26 +11,42 @@ return "Hello, my name is " + name + " and I am " + age + " years old";
1311
function getRemainder(a, b) {
1412

1513

14+
function getTotal(a, b) {
15+
total = a ++ b;
16+
17+
1618
// Use string interpolation here
1719
let Reminder=a%b;
1820
return `The remainder is ${a%b}`;
1921
}
2022

21-
/* ======= TESTS - DO NOT MODIFY ===== */
22-
//
23-
// To run these tests type `node 1-syntax-errors.js` into your terminal
23+
/* ======= TESTS - DO NOT MODIFY =====
24+
There are some Tests in this file that will help you work out if your code is working.
2425
25-
function test(test_name, expr) {
26+
To run these tests type `node 1-syntax-errors.js` into your terminal
27+
*/
28+
29+
const util = require('util');
30+
31+
function test(test_name, actual, expected) {
2632
let status;
2733
if (expr) {
2834
status = "PASSED";
2935
} else {
3036
status = "FAILED";
37+
if (actual === expected) {
38+
status = "PASSED";
39+
} else {
40+
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
3141
}
3242

3343
console.log(`${test_name}: ${status}`);
3444
}
3545

3646
test("fixed addNumbers function - case 1", addNumbers(3,4,6) === 13);
3747
test("fixed introduceMe function", introduceMe("Sonjide",27) === "Hello, my name is Sonjide and I am 27 years old");
38-
test("fixed getRemainder function", getRemainder(23,5) === "The remainder is 3");
48+
test("fixed getRemainder function", getRemainder(23,5) === "The remainder is 3");
49+
=======
50+
test("fixed addNumbers function - case 1", addNumbers(3, 4, 6), 13);
51+
test("fixed introduceMe function", introduceMe("Sonjide", 27), "Hello, my name is Sonjide and I am 27 years old");
52+
test("fixed getTotal function", getTotal(23, 5), "The total is 28");

week-1/2-mandatory/2-logic-error.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function multiply(a, b, c) {
1313
return a * b * c;
1414
}
1515

16-
/* ======= TESTS - DO NOT MODIFY =====
16+
/* ======= TESTS - DO NOT MODIFY =====
1717
There are some Tests in this file that will help you work out if your code is working.
1818
1919
To run these tests type `node 2-logic-error` into your terminal
@@ -32,4 +32,20 @@ function test(test_name, expr) {
3232

3333
test("fixed trimWord function", trimWord(" CodeYourFuture ") === "CodeYourFuture");
3434
test("fixed wordLength function", getWordLength("A wild sentence appeared!") === 25);
35-
test("fixed multiply function", multiply(2,3,6) === 36);
35+
test("fixed multiply function", multiply(2,3,6) === 36);
36+
const util = require('util');
37+
38+
function test(test_name, actual, expected) {
39+
let status;
40+
if (actual === expected) {
41+
status = "PASSED";
42+
} else {
43+
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
44+
}
45+
46+
console.log(`${test_name}: ${status}`);
47+
}
48+
49+
test("fixed trimWord function", trimWord(" CodeYourFuture "), "CodeYourFuture");
50+
test("fixed wordLength function", getWordLength("A wild sentence appeared!"), 25);
51+
test("fixed multiply function", multiply(2, 3, 6), 36);

week-1/2-mandatory/3-function-output.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,42 @@ function concatenate(firstWord, secondWord, thirdWord) {
1212

1313
console.log(firstWord.concat(" ").concat(secondWord).concat(" ").concat(thirdWord));
1414
return firstWord.concat(" ").concat(secondWord).concat(" ").concat(thirdWord);
15+
// Write the body of this function to concatenate three words together.
16+
// Look at the test case below to understand what this function is expected to return.
1517
}
1618

17-
/* ======= TESTS - DO NOT MODIFY =====
19+
/* ======= TESTS - DO NOT MODIFY =====
1820
There are some Tests in this file that will help you work out if your code is working.
19-
2021
To run these tests type `node 3-function-output` into your terminal
2122
*/
2223

23-
function test(test_name, expr) {
24-
let status;
25-
if (expr) {
26-
status = "PASSED";
27-
} else {
28-
status = "FAILED";
29-
}
24+
const util = require('util');
25+
26+
function test(test_name, actual, expected) {
27+
let status;
28+
if (actual === expected) {
29+
status = "PASSED";
30+
} else {
31+
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
32+
}
3033

31-
console.log(`${test_name}: ${status}`);
34+
console.log(`${test_name}: ${status}`);
3235
}
3336

3437
test(
3538
"concatenate function - case 1 works",
36-
concatenate("code", "your", "future") === "code your future"
39+
concatenate('code', 'your', 'future'),
40+
"code your future"
3741
);
3842

3943
test(
4044
"concatenate function - case 2 works",
41-
concatenate("I", "like", "pizza") === "I like pizza"
45+
concatenate('I', 'like', 'pizza'),
46+
"I like pizza"
4247
);
4348

4449
test(
4550
"concatenate function - case 3 works",
46-
concatenate("I", "am", 13) === "I am 13"
51+
concatenate('I', 'am', 13),
52+
"I am 13"
4753
);

week-1/2-mandatory/4-tax.js

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function calculateSalesTax(priceOfProduct) {
1616
===================
1717
The business has informed you that prices must have 2 decimal places
1818
They must also start with the currency symbol
19-
Write a function that transforms numbers into the format £0.00
19+
Write a function that adds tax to a number, and then transforms the total into the format £0.00
2020
2121
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
2222
*/
@@ -26,37 +26,31 @@ var price=calculateSalesTax(a);
2626

2727
return ${price.toFixed(2)}`;
2828
}
29+
=======
30+
function addTaxAndFormatCurrency() {}
2931

30-
/* ======= TESTS - DO NOT MODIFY =====
32+
/* ======= TESTS - DO NOT MODIFY =====
3133
There are some Tests in this file that will help you work out if your code is working.
32-
3334
To run these tests type `node 4-tax.js` into your terminal
3435
*/
3536

36-
function test(test_name, expr) {
37-
let status;
38-
if (expr) {
39-
status = "PASSED";
40-
} else {
41-
status = "FAILED";
42-
}
37+
const util = require('util');
38+
39+
function test(test_name, actual, expected) {
40+
let status;
41+
if (actual === expected) {
42+
status = "PASSED";
43+
} else {
44+
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
45+
}
4346

44-
console.log(`${test_name}: ${status}`);
47+
console.log(`${test_name}: ${status}`);
4548
}
4649

47-
test("calculateSalesTax function - case 1 works", calculateSalesTax(15) === 18);
48-
test(
49-
"calculateSalesTax function - case 2 works",
50-
calculateSalesTax(17.5) === 21
51-
);
52-
test(
53-
"calculateSalesTax function - case 3 works",
54-
calculateSalesTax(34) === 40.8
55-
);
56-
57-
test("formatCurrency function - case 1 works", formatCurrency(15) === "£18.00");
58-
test(
59-
"formatCurrency function - case 2 works",
60-
formatCurrency(17.5) === "£21.00"
61-
);
62-
test("formatCurrency function - case 3 works", formatCurrency(34) === "£40.80");
50+
test("calculateSalesTax function - case 1 works", calculateSalesTax(15), 18)
51+
test("calculateSalesTax function - case 2 works", calculateSalesTax(17.5), 21)
52+
test("calculateSalesTax function - case 3 works", calculateSalesTax(34), 40.8)
53+
54+
test("addTaxAndFormatCurrency function - case 1 works", addTaxAndFormatCurrency(15), "£18.00")
55+
test("addTaxAndFormatCurrency function - case 2 works", addTaxAndFormatCurrency(17.5), "£21.00")
56+
test("addTaxAndFormatCurrency function - case 3 works", addTaxAndFormatCurrency(34), "£40.80")

week-1/3-extra/1-currency-conversion.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ function convertToUSD(price) {
1515
===================
1616
The business is now breaking into the Brazilian market
1717
Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £)
18-
They have also decided that they should add a 1% fee to all foreign transactions
19-
Find a way to add 1% to all currency conversions (think about the DRY principle)
18+
They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL.
2019
*/
2120

2221
function convertToBRL(price) {
@@ -32,16 +31,18 @@ There are some Tests in this file that will help you work out if your code is wo
3231
To run these tests type `node 1-currency-conversion` into your terminal
3332
*/
3433

35-
function test(test_name, expr) {
36-
let status;
37-
if (expr) {
38-
status = "PASSED";
39-
} else {
40-
status = "FAILED";
41-
}
34+
const util = require('util');
4235

43-
console.log(`${test_name}: ${status}`);
36+
function test(test_name, actual, expected) {
37+
let status;
38+
if (actual === expected) {
39+
status = "PASSED";
40+
} else {
41+
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
42+
}
43+
44+
console.log(`${test_name}: ${status}`);
4445
}
4546

46-
test("convertToUSD function works", convertToUSD(32) === 44.8);
47-
test("convertToBRL function works", convertToBRL(30) === 172.71);
47+
test("convertToUSD function works", convertToUSD(32), 44.8);
48+
test("convertToBRL function works", convertToBRL(30), 169.29);

week-1/3-extra/2-piping.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,24 @@ test('add function - case 2 works', add(2.4,5.3) === 7.7);
6060
test('multiply function works', multiply(2,3) === 6);
6161
test('format function works', format(16) === "£16");
6262
test('badCode variable correctly assigned', badCode === "£24");
63-
test('goodCode variable correctly assigned', goodCode === "£24");
63+
test('goodCode variable correctly assigned', goodCode === "£24");
64+
=======
65+
const util = require('util');
66+
67+
function test(test_name, actual, expected) {
68+
let status;
69+
if (actual === expected) {
70+
status = "PASSED";
71+
} else {
72+
status = `FAILED: expected: ${util.inspect(expected)} but your code returned: ${util.inspect(actual)}`;
73+
}
74+
75+
console.log(`${test_name}: ${status}`);
76+
}
77+
78+
test('add function - case 1 works', add(1,3), 4)
79+
test('add function - case 2 works', add(2.4,5), 7.4)
80+
test('multiply function works', multiply(2,3), 6)
81+
test('format function works', format(16), "£16")
82+
test('badCode variable correctly assigned', badCode, "£24")
83+
test('goodCode variable correctly assigned', goodCode, "£24")

week-1/3-extra/3-magic-8-ball.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ function shakeBall() {
5858
//answers[Math.floor(Math.random()*answers.length)]
5959
// The answer should come from shaking the ball
6060
//let answer;
61+
}
6162

62-
// When checking the answer, we should tell someone if the answer is
63+
// This function should say whether the answer it is given is
6364
// - very positive
6465
// - positive
6566
// - negative
@@ -112,17 +113,20 @@ if(answer==3){
112113
return "very negative";
113114
}
114115

116+
=======
117+
// This function should expect to be called with any value which was returned by the shakeBall function.
118+
function checkAnswer(answer) {
115119
}
116120

117-
/* ======= TESTS - DO NOT MODIFY =====
121+
/* ======= TESTS - DO NOT MODIFY =====
118122
There are some Tests in this file that will help you work out if your code is working.
119123
120124
To run these tests type `node 3-magic-8-ball.js` into your terminal
121125
*/
122126

123127
const log = console.log;
124128
let logged;
125-
console.log = function () {
129+
console.log = function() {
126130
log(...arguments);
127131
logged = arguments[0];
128132
};
@@ -148,12 +152,37 @@ function testAll() {
148152
);
149153

150154
test(`shakeBall returns an string answer"`, typeof answer === "string");
155+
156+
test(`shakeBall returns an string answer`, typeof answer === "string");
157+
158+
test(
159+
`checkAnswer("It is decidedly so.") returns "very positive`,
160+
checkAnswer("It is decidedly so.") === "very positive"
161+
)
162+
163+
test(
164+
`checkAnswer("My reply is no.") returns "very negative`,
165+
checkAnswer("My reply is no.") === "very negative"
166+
)
167+
151168
test(
152169
`checkAnswer returns the level of positivity"`,
153170
["very positive", "positive", "negative", "very negative"].includes(
154171
checkAnswer(answer)
155172
)
156173
);
174+
const answers = new Set();
175+
for (let i = 0; i < 10; ++i) {
176+
answers.add(shakeBall());
177+
}
178+
test(
179+
`shakeBall returns different answers`,
180+
answers.size > 1,
181+
);
182+
test(
183+
`checkAnswer returns different answers`,
184+
new Set(Array.from(answers.values()).map(checkAnswer)).size > 1,
185+
);
157186
}
158187

159188
testAll();

0 commit comments

Comments
 (0)