update - #436
Conversation
JDysiewicz
left a comment
There was a problem hiding this comment.
looking good so far, seems you're taking to JS well :D Careful of not using var (stick to const, or if necessary use let), and remember that variables in JS are case-sensitive.
| @@ -1,3 +1,7 @@ | |||
| // Start by creating a variable `message` | |||
| var message = "This is a string"; | |||
There was a problem hiding this comment.
try to avoid using var; it can cause issues with scoping https://www.freecodecamp.org/news/var-let-and-const-whats-the-difference/ (you're not expected to understand what this means currently, just here in case you're interested). Try to always use const, then, if the variable needs reassigning, delcare with let instead
| numberOfStudents = 15; | ||
| numberOfMentors = 8; | ||
| total = numberOfMentors + numberOfStudents |
There was a problem hiding this comment.
Variables in JavaScript need to be "declared"; this means you prefix the variable name with let or const (e.g. const numberOfStudents = x, let numberOfMentors = y. This is effectively letting JS know that numberOfStudents refers to a variable, instead of being some other key word. This is causing some tests to fail
| @@ -1,7 +1,7 @@ | |||
| function halve(number) { | |||
| // complete the function here | |||
| return Number*.5 | |||
There was a problem hiding this comment.
variables are case-sensitive; in this case you want to refer to the number variable; but instead you're referring to something called Number (which, incidentally, is a thing that exists in JS)
| // Declare your function first | ||
|
|
||
| function name(a,b) { | ||
| return a/b |
There was a problem hiding this comment.
What would happen if b = 0; you would execute a/0 - give this a try and see what happens; have a think about how you might handle that situation (note - this is more advanced than strictly necessary at this point, but it's always good to think ahead)
| @@ -1,4 +1,7 @@ | |||
| // Declare your function here | |||
| function createLongGreeting(a, b) { | |||
| return "I am " + a + " and I am " + b + " years old" | |||
There was a problem hiding this comment.
As a general comment, how might you rewrite this as a template string? Usually, template strings are preferred to string concatenation (especially when there are many variables involved), as it's usually more readable.
|
Make sure to stick to the naming convention specified in the template for naming your PRs; it makes locating and organizing them far easier. |
| function calculateSalesTax() {} | ||
|
|
||
| function calculateSalesTax(sales) { | ||
| const calcTax = sales * 0.2 + sales; | ||
| return calcTax; | ||
| } |
There was a problem hiding this comment.
You're declaring the same function name twice here, which is why one of your tests is failing. You can remove the declaration on line 9.
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?
getting a function into a function
What do you still not understand?
Any other notes?
View rendered exercises/B-hello-world/README.md