Glasgow Class 6 - Malkit Benning - JS - Week 1 - #473
Conversation
Got all mandatory correct
last test failing
| */ | ||
| function checkAnswer(answer) { | ||
| //Write your code in here | ||
|
|
There was a problem hiding this comment.
Veryyyy long "if else" statement don't you think? Try to break down your array into 4 small ones. Then we can use them to compare if the inbound answer is inside one of the arrays. Also, this function doesn't correlate with your array at all.
There was a problem hiding this comment.
Wow! Maksim - this is so useful. Thank you for taking the time to review! I'm also very impressed that you fixed the bug in your version. I made a few corrections based on your advice. Hope I understood your feedback correctly.
| function shakeBall() { | ||
| //Write your code in here | ||
| console.log("The ball has shaken!"); | ||
| const predictions = [ |
There was a problem hiding this comment.
We also can set our array outside of the function, for better readability.
changed several if conditions into fewer inspect array conditions.
changed position of setupFilesAfterEnv and included in two places. This fixed bug
This reverts commit 3b3abb0.
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(preTax) { | ||
| return preTax * 1.2; |
There was a problem hiding this comment.
Hi Malkit, You doing great even you cover the extra one. in calculateSalesTax function return you multiply preTax with 1.2. I think it should be 0.2.
There was a problem hiding this comment.
I believe in this case the multiplying by 1.2 is correct as the script is expecting it to return the value with sales tax added, however the name of the function doesn't make this clear. Maybe it would be better if the function was named calculateAndAddSalesTax(preTax)
There was a problem hiding this comment.
I agree Michael then name of the function could be more meaningful.
msimmdev
left a comment
There was a problem hiding this comment.
Praise: Generally very good answers to the exercises Mal. Well done on doing the extra exercises as well.
|
|
||
| function getTotal(a, b) { | ||
| total = a ++ b; | ||
| total = a + b; |
There was a problem hiding this comment.
Suggestion: use the let keyword to declare the variable
e.g. let total = a + b
The code will work without it but using let scopes the variable to the getTotal function. Without let is there was another function that used a variable called total you could see conflicts.
| @@ -1,14 +1,17 @@ | |||
| // Add comments to explain what this function does. You're meant to use Google! | |||
| // This function generates a random number between 0 and 10 | |||
There was a problem hiding this comment.
Thought: This is correct, but it's worth noting that the number may not be an integer, and could be 0 but cannot be 10.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random for more info
| } | ||
|
|
||
| // Add comments to explain what this function does. You're meant to use Google! | ||
| // The concat() method joins two or more strings. |
There was a problem hiding this comment.
Nitpick: you've described what the concat method does, but not what the combine2Words function does. A better description would be
combine2words returns a string of word1 and word2 joined together
| } | ||
|
|
||
| function concatenate(firstWord, secondWord, thirdWord) { | ||
| return firstWord.concat(" ", secondWord, " ", thirdWord); |
There was a problem hiding this comment.
Nitpick: This is fine, but reads a little funny to me. you could also do something like this
return `${firstWord} ${secondWord} ${thirdWord}`
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(preTax) { | ||
| return preTax * 1.2; |
There was a problem hiding this comment.
I believe in this case the multiplying by 1.2 is correct as the script is expecting it to return the value with sales tax added, however the name of the function doesn't make this clear. Maybe it would be better if the function was named calculateAndAddSalesTax(preTax)
| function convertToBRL() {} | ||
| function convertToBRL(gbp) { | ||
| let minusCommission = gbp * 0.99; | ||
| let real = (minusCommission * 5.7).toFixed(2); |
There was a problem hiding this comment.
Suggestion: Avoid using the toFixed for math operations, as toFixed converts the number to a string. For a pure math function it is better to use the Math.round(val) function to avoid the conversion to a string.
| /* BETTER PRACTICE */ | ||
|
|
||
| let goodCode = | ||
| let goodCode = add(startingValue, 10); |
There was a problem hiding this comment.
Suggestion: While you've correctly broken down the code into appropriate lines, it would be better to use meaningful variable names rather than goodCode
There was a problem hiding this comment.
Thanks Michael, I changed the names of the intermediate values, but kept the last variable name as goodCode as it is used in the actual test.
| Outlook not so good. | ||
| Very doubtful. | ||
| */ | ||
| const predictions = [ |
There was a problem hiding this comment.
Suggestion: Repeating the options from the 4 arrays below in one large predictions array will be difficult to maintain for future changes instead you can create the predictions array after you've defined the other 4.
let allAnswers = [...vposArr , ...posArr , ...negArr , ...vnegArr];
| function shakeBall() { | ||
| //Write your code in here | ||
| console.log("The ball has shaken!"); | ||
| let randomNum = Math.floor(Math.random() * 20) + 1; |
There was a problem hiding this comment.
Issue: I think adding the +1 here is incorrect and could give an 'index out of bounds' error if the Math.floor(Math.random() * 20) returns 19. This is because JavaScript arrays are zero indexed meaning in an array of 20 items the first index is 0 and the last is 19. By adding one you are changing the range of values instead from 1 to 20.
Suggestion: Don't hard code the number 20, if someone removes an item from predictions without updating this it will break. Instead use predictions.length
Changes incorporated after Michael's review
comment removed
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? Video explanations
What did you find hard? Jest in general. Coding from a test perspective.
What do you still not understand? Where I went wrong with last answer for Magic 8 Ball
Any other notes?