WM4_Dawit-Abraha_JavaScript_Core-1_Week-1 - #323
Conversation
Mesgna616
left a comment
There was a problem hiding this comment.
Dawit, your codes are neat and easy to read and understand them. And the way you tackle the problems is good and i like analytical approach.
kawaMANMI
left a comment
There was a problem hiding this comment.
Well done Dawit! overall very good starting in JavaScript
| var messageStart = "My name is"; | ||
| var messageMiddle = "and my name is"; | ||
| var messageEnd = "charactors long"; | ||
| var nameLength = name.nameLength; |
There was a problem hiding this comment.
I am not clear what do yo mean by nameLength = name.nameLength? where did you already declared nameLength
There was a problem hiding this comment.
I appreciate the comments. I'll make it right.
| function halve(number) { | ||
| var number = 12; | ||
| // complete the function here | ||
| return number - (number / 2); |
There was a problem hiding this comment.
nice way to define halve number - (number / 2) you can also just divide the
number by 2
| @@ -1,7 +1,11 @@ | |||
| function triple(number) { | |||
| // complete function here | |||
| var number = 12; | |||
There was a problem hiding this comment.
I think you don't need write step 3 (var number = 12;) as passed "number" as parameter in the function.
| return word1.concat(word2); | ||
| } | ||
| //* | ||
| // This function will join the two words without space between them. |
There was a problem hiding this comment.
| // This function will join the two words without space between them. | |
| // This function will join the two words with a space between them. |
| } | ||
|
|
||
| //* | ||
| // The random() method returns a random value that is greater than or equal to 0.0 and less than 1.0. |
| 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).concat(" ", thirdWord); |
There was a problem hiding this comment.
I like the way you've called .concat() on the result of .concat()! Are you able to explain why this works?
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(price) { | ||
| let salesTax = (price * 20) / 100; |
There was a problem hiding this comment.
This confused me to begin with as to why you were multiplying the price by 20. One of the reasons is that I have no idea what the significance of that number is. In the industry we'd refer to this as a "magic number". It's considered better to treat it as a named constant defined somewhere in your code. Some people/organisations will capitalize shared constants, something like:
const TAX_RATE = 20;
function calculateSalesTax(price) {
let tax = price * TAX_RATE / 100;
return price + tax;
}
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?
What did you find hard?
What do you still not understand?
Any other notes?
View rendered exercises/C-variables/README.md