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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/node_modules/
/package-lock.json
.idea
.vscode
16 changes: 14 additions & 2 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(price) {
const EXCHANGE_RATE = 1.4;
let priceInUSD = price * EXCHANGE_RATE;
let priceInUSDFormatted = priceInUSD.toFixed(2)
return Number(priceInUSDFormatted);
}

/*
CURRENCY CONVERSION
Expand All @@ -15,7 +20,14 @@ 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) {
const EXCHANGE_RATE = 5.7;
let amountInBRL = price * EXCHANGE_RATE;
let fee = amountInBRL * 0.01;
let finalAmountInBRL = amountInBRL - fee;
let finalAmountInBRLFormatted = finalAmountInBRL.toFixed(2);
return Number(finalAmountInBRLFormatted);
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
19 changes: 11 additions & 8 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,29 @@
the final result to the variable goodCode
*/

function add() {

function add(a, b) {
return a + b;
}

function multiply() {

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

function format() {

function format(num) {
return `£${num}`

Choose a reason for hiding this comment

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

Nice string interpolation here!

}

const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
let badCode = format(multiply(add(startingValue, 10), 2));
//This code can be seen as bad practice because multiple methods are used in one line which makes it hard to determine the results from each methods execution. It is confusing and hard to follow.

Choose a reason for hiding this comment

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

My explanation was:

//Multiple methods are used in one line which makes it hard to determine the results from each methods execution. It is confusing and hard to follow.

Choose a reason for hiding this comment

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

Nice answer Schboostie

/* BETTER PRACTICE */

let goodCode =
let sum = add(startingValue, 10);
let doubledSum = multiply(sum, 2);
let goodCode = format(doubledSum);

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
65 changes: 60 additions & 5 deletions extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@

// This should log "The ball has shaken!"
// and return the answer.
function shakeBall() {
//Write your code in here
}
const veryPositive = "very positive";
const positive = "positive";
const negative = "negative";
const veryNegative = "very negative";
const allResults = [veryPositive, positive, negative, veryNegative]


/*
This function should say whether the answer it is given is
Expand All @@ -58,10 +61,62 @@ 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

const veryPositiveAnswers = [
"It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes - definitely.",
"You may rely on it.",
];

const positiveAnswers = [
"As I see it, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes.",
];

const negativeAnswers = [
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again.",
];

const veryNegativeAnswers = [
"Don't count on it.",
"My reply is no.",
"My sources say no.",
"Outlook not so good.",
"Very doubtful.",
];

let allAnswers = [veryPositiveAnswers, positiveAnswers, negativeAnswers, veryNegativeAnswers];

function findRandomIndex(max){
return Math.floor(Math.random() * max);

Choose a reason for hiding this comment

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

Great use of max here!

}

function shakeBall() {
console.log("The ball has shaken!");
let num1 = findRandomIndex(4);
let num2 = findRandomIndex(5);
return allAnswers[num1][num2];

Choose a reason for hiding this comment

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

Why are you returning two indices here?

Choose a reason for hiding this comment

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

Ah, I think I see. Do you need to call findRandomIndex within the shakeBall function so that it changes the output each time?


}

function checkAnswer(answer) {

Choose a reason for hiding this comment

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

I am not sure what this is doing (am new to javascript). Could you please explain? Remember to focus on readability. Looks great though and it's awesome to see all the tests passing.

let index;
allAnswers.map((answerItem, i)=>{
if(answerItem.includes(answer)){
index = i;
}
})
return allResults[index];
}
/*
==================================
======= TESTS - DO NOT MODIFY =====
Expand Down
12 changes: 6 additions & 6 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// There are syntax errors in this code - can you fix it to pass the tests?

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

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`;

Choose a reason for hiding this comment

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

Good use of back tick when adding variables to a string.

}

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

return "The total is total";
let total = a + b;
return `The total is ${total}`;

Choose a reason for hiding this comment

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

Nice!

}

/*
Expand Down
7 changes: 3 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// 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;
return a * b * c;
}

Choose a reason for hiding this comment

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

All functions looking good here, Iryna!


/*
Expand Down
6 changes: 5 additions & 1 deletion mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
// Add comments to explain what this function does. You're meant to use Google!
// Returns a random integer from 0 to 9

Choose a reason for hiding this comment

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

You could add further comments to explain how Math.random() returns a decimal value which is then scaled to a desired range.

Choose a reason for hiding this comment

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

Agreed. It'll be helpful for collaborators to know what the random operator does.

Also, is 9 the highest output of this function? What if math.random selects 0.9, for example?

Copy link
Author

@IrynaLypnyk IrynaLypnyk Feb 22, 2023

Choose a reason for hiding this comment

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

Oh, yes, you are right. Math.random() returns a decimal value, and it can be scaled more than just to 9. But if to speak just about my function - it returns form 0 to 9. Thank you, Shahid and Katie!

function getRandomNumber() {
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!
//Concatenate strings,numbers, arrays:

Choose a reason for hiding this comment

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

Nice start but think we can add a little more detail here. What specifically is this function doing?

Also, concat can be used to concatanate strings and arrays, but can it concatanate numbers?

function combine2Words(word1, word2) {
return word1.concat(word2);
return word1.concat(word2);
}

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 this function is expected to return.

return firstWord.concat(' ', secondWord, ' ', thirdWord);

Choose a reason for hiding this comment

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

Nice one!

}

/*
Expand Down
10 changes: 8 additions & 2 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}
function calculateSalesTax(price) {
return price * 1.2;
}

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

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(number) {
let tax = calculateSalesTax(number);

Choose a reason for hiding this comment

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

I really like the use of the tax variable to break down the stages of the function.

Choose a reason for hiding this comment

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

Me too!

let taxFormatted = tax.toFixed(2)
return `£${taxFormatted}`
}

/*
===================================================
Expand Down