London | 26-ITP-January | Laura C | Sprint 2 | Structuring and Testing Data#960
London | 26-ITP-January | Laura C | Sprint 2 | Structuring and Testing Data#960lauracs24 wants to merge 12 commits intoCodeYourFuture:mainfrom
Conversation
…redeclaration in 1.js
cjyuan
left a comment
There was a problem hiding this comment.
Both the code and the explanations are good.
I only have a question and some suggestions.
| const num = 103; | ||
| // I think the program will print 3 every time. | ||
| // Even though different numbers are passed into the function, | ||
| // the function is using the variable 'num', which is 103. |
There was a problem hiding this comment.
It is possible to have a global variable and a parameter named num in a script. For example,
const num = 103;
function getLastDigit(num) {
return num.toString().slice(-1);
}Can you find out why?
There was a problem hiding this comment.
Ah I think the issue was not the shared variable name, but that the function did not define a parameter. I have updated my explanation to reflect this
There was a problem hiding this comment.
Your change is good, and you are right about the function not having a parameter.
I meant to point out these two concepts, "identifier scope and identifier resolution, in the context of JavaScript programming". ChatGPT can give a good explanation.
|
Changes look good. Well done. |
Self checklist
Changelist
I worked through all Sprint 2 exercises by predicting errors, running the code with node, and explaining why issues occurred before fixing them. In the debug section, I identified logic problems and corrected the functions so they returned the correct values. I also implemented the required functions (calculateBMI, toUpperSnakeCase, and toPounds) and completed the interpret task by analysing the code step by step and answering the questions.
Questions
What is a reliable way of learning javascript easily and testing yourself?