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

Week8 #1036

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open

Week8 #1036

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d55d503
Completed mandatory exercises
andsemenov Apr 27, 2020
7686570
Completed extra exercises
andsemenov Apr 27, 2020
3f690b8
Changed 2-piping exercise
andsemenov May 1, 2020
3803243
Use last year's exercises for scotland class 4
May 2, 2020
dd4a1b2
Add Loops exercises
May 2, 2020
5eee5fb
Add expected result to while loop exercise
May 2, 2020
1b05858
Remove array method exercises
May 2, 2020
faac018
Add more While loop exercises
May 2, 2020
da65354
Revert "Add more While loop exercises"
May 2, 2020
8e466c8
Working while exercises
May 2, 2020
412666e
homework
May 3, 2020
0ac118b
Revert "homework"
May 3, 2020
c4f12f2
Add Old Homework To Scotland Class 4 Branch (#852)
ChrisOwen101 May 12, 2020
8499fee
restructure homework
rarmatei May 24, 2020
a64e1f3
simplify homework
rarmatei May 25, 2020
dd6f0dc
remote this keyword from homework
rarmatei May 25, 2020
37f6e1e
Merge pull request #878 from rarmatei/class4-js-wk-4
rarmatei May 28, 2020
c603c7b
update homework
rarmatei May 29, 2020
d6bed7c
update
rarmatei May 29, 2020
2b0206a
add itworked file
rarmatei May 30, 2020
d914af5
Merge branch 'scotland-class4' of https://github.com/CodeYourFuture/j…
andsemenov May 30, 2020
7b33f98
move exercises for week5
rarmatei Jun 5, 2020
ff90e30
add images to exercise 1 homework
rarmatei Jun 5, 2020
fd49d01
add image links
rarmatei Jun 5, 2020
53c9feb
add task 6
rarmatei Jun 5, 2020
b1add69
move khanacademy back into mandatory
rarmatei Jun 6, 2020
e5e45c5
Merge branch 'scotland-class4' of https://github.com/CodeYourFuture/j…
andsemenov Jun 6, 2020
a473f31
Merge branch 'master' of github.com:CodeYourFuture/js-exercises into …
rarmatei Jun 9, 2020
b4eb201
restructure week6
rarmatei Jun 9, 2020
3e32b89
simplify exercise 1
rarmatei Jun 12, 2020
72e3e21
simplify dom exercise
rarmatei Jun 12, 2020
5283e47
hide movie loader
rarmatei Jun 12, 2020
c0c8b8b
add more exercise details
rarmatei Jun 12, 2020
489be3a
Merge branch 'scotland-class4' of https://github.com/CodeYourFuture/j…
andsemenov Jun 13, 2020
d8d5674
Week-7 add InClass Exercises
r-darby Jun 27, 2020
6b6492b
Merge branch 'scotland-class4' of https://github.com/CodeYourFuture/j…
andsemenov Jun 27, 2020
11ef69d
Completed InClass exercises
andsemenov Jun 29, 2020
aac0167
Create Function InClass exercises
r-darby Jun 30, 2020
379c59e
add fetch and API exercises
rarmatei Jul 3, 2020
0126d48
Added something
andsemenov Jul 4, 2020
07c2594
Merge branch 'scotland-class4' of https://github.com/CodeYourFuture/j…
andsemenov Jul 4, 2020
8af4c24
Added INCLASS exercises
andsemenov Jul 9, 2020
7f246e5
Added 2-fetch-exercise
andsemenov Jul 9, 2020
9269985
Added homework exercises
andsemenov Jul 11, 2020
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
Binary file modified .DS_Store
Binary file not shown.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]
}
20 changes: 13 additions & 7 deletions week-1/Homework/extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(priceGBP) {
let priceUSD = priceGBP * 1.4;
return priceUSD;
}

/*
CURRENCY FORMATTING
Expand All @@ -16,20 +19,23 @@ function convertToUSD() {}
Find a way to add 1% to all currency conversions (think about the DRY principle)
*/

function convertToBRL() {}
function convertToBRL(priceGBP) {
let priceBRL = priceGBP * 5.7 * 1.01;
return priceBRL;
}

/* ======= TESTS - DO NOT MODIFY ===== */

function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED"
status = "PASSED";
} else {
status = "FAILED"
status = "FAILED";
}

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

test('convertToUSD function works', convertToUSD(32) === 44.8)
test('convertToBRL function works', convertToBRL(30) === 172.71)
test("convertToUSD function works", convertToUSD(32) === 44.8);
test("convertToBRL function works", convertToBRL(30) === 172.71);
45 changes: 25 additions & 20 deletions week-1/Homework/extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,49 @@
3. Write a more readable version of what you wrote in step 2 under the BETTER PRACTICE comment. Assign
the final result to the variable goodCode
*/

function add() {

let a, b, c, d;
function add(a, b) {
let summa = Math.round((a + b) * 10) / 10;
return summa;
}

function multiply() {

function multiply(b, c) {
return b * c;
}

function format() {

function format(d) {
return "£" + d;
}

const startingValue = 2
console.log(add(1, 3));
console.log(add(2.4, 5.3));
const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =

let badCode = format(multiply(add(10, startingValue), 2));

/* BETTER PRACTICE */

let goodCode =
addValue = add(startingValue, 10);
multiplayValue = multiply(addValue, 2);

let goodCode = format(multiplayValue);
/* ======= TESTS - DO NOT MODIFY ===== */

function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED"
status = "PASSED";
} else {
status = "FAILED"
status = "FAILED";
}

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

test('add function - case 1 works', add(1,3) === 4)
test('add function - case 2 works', add(2.4,5.3) === 7.7)
test('multiply function works', multiply(2,3) === 6)
test('format function works', format(16) === "£16")
test('badCode variable correctly assigned', badCode === "£24")
test('goodCode variable correctly assigned', goodCode === "£24")
test("add function - case 1 works", add(1, 3) === 4);
test("add function - case 2 works", add(2.4, 5.3) === 7.7);
test("multiply function works", multiply(2, 3) === 6);
test("format function works", format(16) === "£16");
test("badCode variable correctly assigned", badCode === "£24");
test("goodCode variable correctly assigned", goodCode === "£24");
45 changes: 26 additions & 19 deletions week-1/Homework/mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
// There are syntax errors in this code - can you fix it to pass the tests?

function addNumbers(a b c) {
return a + b + c;
function addNumbers(a, b, c) {
return a + b + c;
}

function introduceMe(name, age)
return "Hello, my name is " + name "and I am " age + "years old";

function introduceMe(name, age) {
return "Hello, my name is " + name + " and I am " + age + " years old";
}
function getRemainder(a, b) {
remainder = a %% b;
remainder = a % b;

// Use string interpolation here
return "The remainder is %{remainder}"
// Use string interpolation here
return `The remainder is ${remainder}`;
}

/* ======= TESTS - DO NOT MODIFY ===== */

function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED"
} else {
status = "FAILED"
}

console.log(`${test_name}: ${status}`)
let status;
if (expr) {
status = "PASSED";
} else {
status = "FAILED";
}

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

test("fixed addNumbers function - case 1", addNumbers(3,4,6) === 13)
test("fixed introduceMe function", introduceMe("Sonjide",27) === "Hello, my name is Sonjide and I am 27 years old")
test("fixed getRemainder function", getRemainder(23,5) === "The remainder is 3")
test("fixed addNumbers function - case 1", addNumbers(3, 4, 6) === 13);
test(
"fixed introduceMe function",
introduceMe("Sonjide", 27) ===
"Hello, my name is Sonjide and I am 27 years old"
);
test(
"fixed getRemainder function",
getRemainder(23, 5) === "The remainder is 3"
);
25 changes: 15 additions & 10 deletions week-1/Homework/mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
// The syntax for this function is valid but it has an error, find it and fix it.

function trimWord(word) {
return wordtrim();
return word.trim();
}

function getWordLength(word) {
return "word".length()
return word.length;
}

function multiply(a, b, c) {
a * b * c;
return;
return a * b * c;
}

/* ======= TESTS - DO NOT MODIFY ===== */

function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED"
status = "PASSED";
} else {
status = "FAILED"
status = "FAILED";
}

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

test("fixed trimWord function", trimWord(" CodeYourFuture ") === "CodeYourFuture")
test("fixed wordLength function", getWordLength("A wild sentence appeared!") === 25)
test("fixed multiply function", multiply(2,3,6) === 36)
test(
"fixed trimWord function",
trimWord(" CodeYourFuture ") === "CodeYourFuture"
);
test(
"fixed wordLength function",
getWordLength("A wild sentence appeared!") === 25
);
test("fixed multiply function", multiply(2, 3, 6) === 36);
48 changes: 28 additions & 20 deletions week-1/Homework/mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
// Add comments to explain what this function does. You're meant to use Google!
// The function returns pseudorandom number from [0,10)
function getNumber() {
return Math.random() * 10;
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!
// The function concatenates 2 words together
function s(w1, w2) {
return w1.concat(w2);
return w1.concat(w2);
}

function concatenate(firstWord, secondWord, thirdWord) {
// Write the body of this function to concatenate three words together
// Look at the test case below to understand what to expect in return
// Write the body of this function to concatenate three words together
// Look at the test case below to understand what to expect in return
return firstWord.concat(" ", secondWord, " ", thirdWord);
}

/* ======= TESTS - DO NOT MODIFY ===== */

function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED"
} else {
status = "FAILED"
}
console.log(`${test_name}: ${status}`)
let status;
if (expr) {
status = "PASSED";
} else {
status = "FAILED";
}

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

test("concatenate function - case 1 works", concatenate('code', 'your', 'future') === "code your future")
test("concatenate function - case 2 works", concatenate('I', 'like', 'pizza') === "I like pizza")
test("concatenate function - case 3 works", concatenate('I', 'am', 13) === "I am 13")

test(
"concatenate function - case 1 works",
concatenate("code", "your", "future") === "code your future"
);
test(
"concatenate function - case 2 works",
concatenate("I", "like", "pizza") === "I like pizza"
);
test(
"concatenate function - case 3 works",
concatenate("I", "am", 13) === "I am 13"
);
40 changes: 27 additions & 13 deletions week-1/Homework/mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
Sales tax is 20% of the price of the product
*/

function calculateSalesTax() {}
function calculateSalesTax(cost) {
let salesTax = (cost * (100 + 20)) / 100;
return salesTax;
}

/*
CURRENCY FORMATTING
Expand All @@ -17,25 +20,36 @@ function calculateSalesTax() {}
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function formatCurrency() {}

function formatCurrency(cost) {
let twoDecimalSalexTax = calculateSalesTax(cost).toFixed(2);
return "£".concat(twoDecimalSalexTax);
}
/* ======= TESTS - DO NOT MODIFY ===== */

function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED"
status = "PASSED";
} else {
status = "FAILED"
status = "FAILED";
}

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

test("calculateSalesTax function - case 1 works", calculateSalesTax(15) === 18)
test("calculateSalesTax function - case 2 works", calculateSalesTax(17.5) === 21)
test("calculateSalesTax function - case 3 works", calculateSalesTax(34) === 40.8)

test("formatCurrency function - case 1 works", formatCurrency(15) === "£18.00")
test("formatCurrency function - case 2 works", formatCurrency(17.5) === "£21.00")
test("formatCurrency function - case 3 works", formatCurrency(34) === "£40.80")
test("calculateSalesTax function - case 1 works", calculateSalesTax(15) === 18);
test(
"calculateSalesTax function - case 2 works",
calculateSalesTax(17.5) === 21
);
test(
"calculateSalesTax function - case 3 works",
calculateSalesTax(34) === 40.8
);

test("formatCurrency function - case 1 works", formatCurrency(15) === "£18.00");
test(
"formatCurrency function - case 2 works",
formatCurrency(17.5) === "£21.00"
);
test("formatCurrency function - case 3 works", formatCurrency(34) === "£40.80");
Loading