Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
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
19 changes: 16 additions & 3 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(price) {

let rate=1.4;
return rate * price;
}

/*
CURRENCY CONVERSION
Expand All @@ -15,9 +19,18 @@ function convertToUSD() {}
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.
*/

function convertToBRL() {}
function convertToBRL( price ) {
let rate = 5.7 ;
let total = price * rate;
let newPrice = total*0.99;
let result = (Math.round(newPrice*100)/100);
return result ;
}




/* ======= TESTS - DO NOT MODIFY =====
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

To run the tests for just this one file, type `npm test -- --testPathPattern 1-currency-conversion` into your terminal
Expand Down
32 changes: 22 additions & 10 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,45 @@
- add 10 to startingValue
- multiply the result by 2
- format it

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() {

function add(num1,num2) {
let result = num1 + num2;
return result;
}

function multiply() {

function multiply(num1,num2) {
let result = num1 * num2;
return result;
}

function format() {

function format(startingValue) {
return (`£` +startingValue);
}

const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
/*The string "£24" meaning that it appears without context or explanation
in the code. This can make the code harder to read and maintain*/
let badCode = "£24";
console.log("The bad code is: " + badCode);

/* BETTER PRACTICE */

let goodCode =

/* ======= TESTS - DO NOT MODIFY =====
let currencySymbol = "£";
let price = 24;
let goodCode = `${currencySymbol}${price}`;
//This code is easy to read and understand, with no unnecessary complexity




/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

To run the tests for just this one file, type `npm test -- --testPathPattern 2-piping` into your terminal
Expand Down
16 changes: 10 additions & 6 deletions extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**

Let's peer into the future using a Magic 8 Ball!
https://en.wikipedia.org/wiki/Magic_8-Ball
https://en.wikipedia.org/wiki/Magic_8-Ball

There are a few steps to being able view the future though:
* Ask a question
Expand Down Expand Up @@ -45,11 +45,12 @@

// This should log "The ball has shaken!"
// and return the answer.
function shakeBall() {
function shakeBall(answer) {
//Write your code in here

}

/*
/*
This function should say whether the answer it is given is
- very positive
- positive
Expand All @@ -58,11 +59,14 @@ function shakeBall() {

This function should expect to be called with any value which was returned by the shakeBall function.
*/
function checkAnswer(answer) {
//Write your code in here
function checkAnswer() {


}

/*


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

Expand Down
15 changes: 9 additions & 6 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// 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) {
let d = a + b + c;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple thoughts, do we need a variable here? And if we do can we name it better?

return d ;
}

function introduceMe(name, age)
return `Hello, my {name}` is "and I am $age years old`;
function introduceMe(name , age){
return `Hello, my name is ${name} and I am ${age} years old`;
}


function getTotal(a, b) {
total = a ++ b;
total = a + b;

return "The total is total";
return "The total is"+" "+ `${total}`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: So here we are using template literals which is nice!! But if so do we need to add strings together? i.e. can we

const personName = "Abdi"

`The greatest name in the world is ${personName}` 

}

/*
Expand Down
8 changes: 4 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// The syntax for these functions is valid but there are some errors, find them and fix them

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

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise : Noice 👍

/*
Expand Down
5 changes: 5 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
function getRandomNumber() {
return Math.random() * 10;
}
//This function is returning a random number between 0 and 10

// Add comments to explain what this function does. You're meant to use Google!
function combine2Words(word1, word2) {
return word1.concat(word2);
}
//The concat() method joins two or more strings together into a new string without modifying the original strings

function concatenate(firstWord, secondWord, thirdWord) {
return firstWord + " "+ secondWord + " "+thirdWord;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Have we answered the question here? I think the goal is to use the concat string method here.

i.e.

const wordOne = "Hello"
const wordTwo = "World"

const combinedWord = wordOne.concat(wordTwo)

How would you concat three words like above?



// Write the body of this function to concatenate three words together.
// Look at the test case below to understand what this function is expected to return.
}
Expand Down
17 changes: 15 additions & 2 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}
function calculateSalesTax( sales) {

let tax = sales * 0.2;
let total = sales + tax;
return total;
}




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

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(sales) {
return "£"+ calculateSalesTax(sales).toFixed(2,0.00);

}



/*
===================================================
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
"homepage": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1#readme",
"devDependencies": {
"jest": "^29.4.3",
"jest-extended": "^3.2.3"
"jest-extended": "^3.2.4"
}
}