Glasgow Class 6 - Man Sang Sin - JS1 - Week 1 - #497
Conversation
- completed tasks 1 - 4
- completed tasks 1 - 3
beardedslav
left a comment
There was a problem hiding this comment.
Good job on completing the coursework! Let me know if you have any further questions on my comments!
| function convertToBRL(amountGBP) { | ||
| convertedAmount = amountGBP * 0.99 * 5.7; | ||
| convertedAmount = convertedAmount.toFixed(2); | ||
| return Number(convertedAmount); |
There was a problem hiding this comment.
Well done! This code works as needed, but you are converting a number to a string and then again to a number. Can you think of a way to do achieve the same result by using only math operations?
There was a problem hiding this comment.
math.round() seems to be a better method.
convertedAmount = (Math.round(convertedAmount * 100)/100)
|
|
||
| // Why can this code be seen as bad practice? Comment your answer. | ||
| let badCode = | ||
| let badCode = `£${((startingValue + 10) * 2)}`; |
There was a problem hiding this comment.
this is a good example of a bad code, but the assignment was to "...perform the following operations using your functions all on one line". You could start it like so:
let badCode = format(multiply(add(
How would you complete it?
There was a problem hiding this comment.
let badCode = format(multiply(add(startingValue, 10)));
| function shakeBall() { | ||
| //Write your code in here | ||
| let answers = veryPositive.concat(positive, negative, veryNegative); | ||
| let randomInteger = Math.floor(Math.random() * 25); |
There was a problem hiding this comment.
That's a nice way to put all the answers in one array. You are concatenating 4 arrays of 5 elements each, are you sure 25 is the best choice for this line? Also what would happen if you were asked to add 2 more answers to every answer type? Is there a way to not to have to rely on a hardcoded number like 25 here?
There was a problem hiding this comment.
20 would be a better value (would give a range between 0 - 19). I think I must've miscounted 5 arrays.
As for not hardcoding the value, counting the variables in the array would be a better option?
I tested out:
let numberOfAnswers = answers.length;
let randomInteger = Math.floor(Math.random() * numberOfAnswers);
and it seems to work.
| return Math.random() * 10; | ||
| } | ||
|
|
||
| // Picks a random number between 0 (inclusive) and 1 (non-inclusive) and multiplies it by 10. |
There was a problem hiding this comment.
This is a good explanation of what happens inside the getRandomNumber() function. How would you describe the end result of calling this function?
Also it's a good practice to add a comment explaining function's behaviour either above or inside the function, rather than below it.
There was a problem hiding this comment.
Returns a value which is between 0 and (but not including) 10.
| // Joins the variable string of word1 to word2 exactly as shown. | ||
|
|
||
| function concatenate(firstWord, secondWord, thirdWord) { | ||
| return firstWord.concat(" ", secondWord, " ", thirdWord); |
There was a problem hiding this comment.
Nice, this is a correct implementation. Is there a way to achieve the same end result without using concat method?
There was a problem hiding this comment.
return ${firstWord} ${secondWord} ${thirdWord}
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(amount) { | ||
| return amount = ((amount * 0.2) + (amount)); |
There was a problem hiding this comment.
Good implementation, but can it be expressed more concisely with fewer maths operations?
There was a problem hiding this comment.
return amount = (1.2 * amount)
Thanks for checking over my work and providing some very useful hints/tips! Your feedback was very helpful. |
change line to call function Co-authored-by: Krzysztof Malinowski <krzysztof+github@malinowski.scot>
mandatory/4 - shortened math function extra/1 - used Math.round() instead of .toFixed() so no need to convert string to number extra/2 - changed code to call function extra/3 - used array.length() to count array instead of hardcoding number of array items
Co-authored-by: Krzysztof Malinowski <krzysztof+github@malinowski.scot>
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?
console.log(), variables, strings, basic calculations
What did you find hard?
8 ball homework
What do you still not understand?
Any other notes?