Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

Glasgow Class 6 - Malkit Benning - JS - Week 1 - #473

Open
malkitbenning wants to merge 9 commits into
CodeYourFuture:masterfrom
malkitbenning:master
Open

Glasgow Class 6 - Malkit Benning - JS - Week 1#473
malkitbenning wants to merge 9 commits into
CodeYourFuture:masterfrom
malkitbenning:master

Conversation

@malkitbenning

Copy link
Copy Markdown

Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in HOW_TO_MARK.md in the root of this repository

Your Details

  • Your Name: Malkit Benning
  • Your City: Glasgow
  • Your Slack Name: Malkit Benning

Homework Details

  • Module: JS
  • Week: 1

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?

Comment thread extra/3-magic-8-ball.js Outdated
*/
function checkAnswer(answer) {
//Write your code in here

@maxbmaapc maxbmaapc Feb 16, 2023

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Comment thread extra/3-magic-8-ball.js Outdated
function shakeBall() {
//Write your code in here
console.log("The ball has shaken!");
const predictions = [

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
Comment thread mandatory/4-tax.js

function calculateSalesTax() {}
function calculateSalesTax(preTax) {
return preTax * 1.2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree Michael then name of the function could be more meaningful.

@msimmdev msimmdev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Praise: Generally very good answers to the exercises Mal. Well done on doing the extra exercises as well.

Comment thread mandatory/1-syntax-errors.js Outdated

function getTotal(a, b) {
total = a ++ b;
total = a + b;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread mandatory/3-function-output.js Outdated
@@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread mandatory/3-function-output.js Outdated
}

function concatenate(firstWord, secondWord, thirdWord) {
return firstWord.concat(" ", secondWord, " ", thirdWord);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nitpick: This is fine, but reads a little funny to me. you could also do something like this
return `${firstWord} ${secondWord} ${thirdWord}`

Comment thread mandatory/4-tax.js

function calculateSalesTax() {}
function calculateSalesTax(preTax) {
return preTax * 1.2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)

Comment thread extra/1-currency-conversion.js Outdated
function convertToBRL() {}
function convertToBRL(gbp) {
let minusCommission = gbp * 0.99;
let real = (minusCommission * 5.7).toFixed(2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread extra/2-piping.js Outdated
/* BETTER PRACTICE */

let goodCode =
let goodCode = add(startingValue, 10);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: While you've correctly broken down the code into appropriate lines, it would be better to use meaningful variable names rather than goodCode

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Comment thread extra/3-magic-8-ball.js Outdated
Outlook not so good.
Very doubtful.
*/
const predictions = [

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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];

Comment thread extra/3-magic-8-ball.js Outdated
function shakeBall() {
//Write your code in here
console.log("The ball has shaken!");
let randomNum = Math.floor(Math.random() * 20) + 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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.

4 participants