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

Js/week 1/davinder #17

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

Conversation

davappler
Copy link

Your Details

Your Name: Davinder Singh
Your City: Birmingham
Your Slack Name: Davinder Singh

Homework Details

Module: Javascript
Week: 1

Corrected all the errors in file in 1-syntax-error.js
Corrected the errors of file 2-logic-error.js
commented the explanations of some functions as asked and wrote a function as indicated.
Implemented two functions calculateSalesTax()  and  formatCurrency()
Implemented the functions in extra folder. functions implemented are

convertToUSD()

and

 convertToBRL()
implemented 3 functions in 2-piping.js
modified a function in 2-piping.js
Modified the function add() in file 2-piping.js in order to pass the test.
completed the task of file 3-magic-5-balls.js
Copy link

@pads pads left a comment

Choose a reason for hiding this comment

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

Good job on this Davinder. Well done for taking on the extra exercises too. I'd have another go at fixing the word trim function in the second exercise. One minor point - it helps improve the legibility of the code by adding spaces between operators, but don't worry too much about this :)

@@ -30,6 +30,6 @@ function test(test_name, expr) {
console.log(`${test_name}: ${status}`)
}

test("fixed trimWord function", trimWord(" CodeYourFuture ") === "CodeYourFuture")
test("fixed trimWord function", trimWord("CodeYourFuture") === "CodeYourFuture")
Copy link

Choose a reason for hiding this comment

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

The test isn't supposed to be modified, try and get the trimWord function to do the right thing and trim the provided string.

function calculateSalesTax() {}
function calculateSalesTax(price)
{
var tax=1.2*price;
Copy link

Choose a reason for hiding this comment

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

Just to make the code easier to read, add a space before you use operators (such as = and *).

function formatCurrency() {}
function formatCurrency(number)
{
tax=calculateSalesTax(number);
Copy link

Choose a reason for hiding this comment

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

This is missing a var before tax.

@@ -5,7 +5,10 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(pound_price)
Copy link

Choose a reason for hiding this comment

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

In JavaScript, the preferred style to use when naming variables is camel case, so here you would have poundPrice.

}

const startingValue = 2

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

let badCode = "Bad practice is when we do not generalise the code ";
Copy link

Choose a reason for hiding this comment

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

Generalising the code is usually a good thing to do but this is not what was meant in the exercise.

  1. Using the variable startingValue as input, perform the following operations using your functions all
    on one line (assign the result to the variable badCode):
  • add 10 to startingValue
  • multiply the result by 2
  • format it

This was asking what you thought about all the code to carry out these operations being on one line.

/* BETTER PRACTICE */

let goodCode =
let goodCode = "A function is useful when it can be applied to many domains, in short we should to generalise it as much as we can";
Copy link

Choose a reason for hiding this comment

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

And here, it was seeing what the code above would look like on multiple lines, so it would read much better (which is definitely good practice that is encouraged here).

@davappler
Copy link
Author

davappler commented Jul 15, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants