NW Class 4 - Maha Malik - JS Core 1 - Week 1 - #110
Conversation
| @@ -1,17 +1,19 @@ | |||
| // Add comments to explain what this function does. You're meant to use Google! | |||
| //My Comment - This function gives a random number by using math.random() and multiplying the value by 10 | |||
There was a problem hiding this comment.
Can you explain the range of the random numbers that will be returned? What range does Math.random() return, and so what will your method return?
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(num) { | ||
| return num *1.2; //Adds 20% to number and gives total price including tax |
There was a problem hiding this comment.
You could also declare 1.2 as a variable called priceWithTax or something similar, or even declare 0.2 as a variable call tax, and then multiply by the price and then add to the price. This would would make it easier to understand what your code is doing. However, your solution has the advantage of being concise. Both approaches work, so it's a matter of taste.
|
|
||
| //CAN ALSO WRITE THIS WAY: | ||
| // function addTaxAndFormatCurrency(num) { | ||
| // var totalPrice= `£${calculateSalesTax(num).toFixed(2)}`; |
There was a problem hiding this comment.
Yes, as discussed in the previous comment, the first is more concise, but sometimes breaking your code down into stages and declaring variables with good names helps to make your code more understandable. It's up to you which you prefer.
| function createGreeting(name) { | ||
| var greeting = `Helloooo ${name}`; | ||
| return greeting.toUpperCase(); | ||
| } |
There was a problem hiding this comment.
the idea of this exercise was to have 2 separate functions, one that returns the name in uppercase and another that returns the greeting by calling the first function to get the name
| 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} ${secondWord} ${thirdWord}`; |
There was a problem hiding this comment.
can you do this using the .concat() method?
|
Your coursework submission has been closed because nobody has interacted with it in six weeks. You are welcome to re-open it to get more feedback. |
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
'Exercises' tasks were fairly easy to understand, but got harder as the tasks progressed. Running tests was very helpful in debugging once I got used to the Jest interface/layout.
What did you find hard?
Struggle with knowing how and when to store functions into variables, and using variables within functions, it'll probably get clearer with practice. Nesting functions is a bit overwhelming, also knowing where to put parameters in nested functions.
What do you still not understand?
Same as above
Any other notes?