Jim-Abdul / hyf-javascript1

HomeWork1 JavaScript
0 stars 0 forks source link

Feedback homework week 2 #1

Open remarcmij opened 6 years ago

remarcmij commented 6 years ago

Hi Jim, here is my feedback on your homework.

When I run your Christmas.js file I get immediately a run-time error:

let y = "Cat";
     ^

SyntaxError: Identifier 'y' has already been declared
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:599:28)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

That means I can't continue the review until you make corrections. How did you test your code? Please make sure that what you give me to review is able to run without requiring modifications from my side.

Let me know when it is corrected and I'll look again.

Jim-Abdul commented 6 years ago

Thanks mr.Jim for your feedback, I fixed it , i am looking forward to hearing from you the new feedback.

remarcmij commented 6 years ago

Hi Jim,

Here is my updated feedback:

exercise 3

exercise 4

exercise 5

let m = "";
if (z > a) {
  let m = z;
}
else {
  let m = a
}

console.log(m);

All variables declared with let have block scope. Therefore the variables m inside the if and else block are different from the first m variable. When you console.log the variable m you will see that it is an empty string and not the highest of the two numbers. If all is well you should have seen in VSCode that the m variables inside the if statement are green underlined by eslint. You should follow up on warnings like that. See if you can solve the bug.

Also take note of the formatting if the if statement.

Note: if you want to declare a variable without initialising it just do let m;. This declares the variable but leaves its value undefined. There is no point in assigning it an empty string as you did in let m = "";

Besides using an if statement, there is also another way of finding the highest of two numbers. Google for 'mdn math' and see what you can find.

exercise 6

exercise 7

exercise 8

if (name === age) {
    console.log(name + 'and' + age + 'are the same type');
}
if (name === arr) {
  console.log(name + 'and' + arr + 'are the same type');
}
...

Bottom line: still one bug to fix.