nodeschool / discussions

:school::speech_balloon: need help with nodeschool? or just wanna ask a question? open an issue on this repo!
489 stars 107 forks source link

[Scope Chains]: Lesson 3 - Global Scope & Shadowing #1371

Closed edrickchu closed 9 years ago

edrickchu commented 9 years ago

Need help with this please!

Your Mission
Starting with your solution from the previous lesson, assign a value to quux
inside foo() (don't use var or let). The value should be different to the
value assigned when defining quux inside zip().

Once complete, execute scope-chains-closures verify to verify your solution.

This is my code: function foo() { quux = 15; function zip() { var quux = 2; } }

This is the error I get:

    operator: equal
    expected:
      '(global)\n\tfoo()\n\t- var bar\n\t- quux = ?\n\t\tzip()\n\t\t- var quux'
    actual:
      '(global)\n\tfoo()\n\t- quux = ?\n\t\tzip()\n\t\t- var quux'

npm -v = 2.12.1 node -v = v0.12.7

Plmk. Thanks!

jesstelford commented 9 years ago

The output is a little hard to read, but once you remove those \n and \t it becomes more obvious what the differences are:

expected:

(global)
  foo()
  - var bar
  - quux = ?
    zip()
    - var quux

actual:

(global)
  foo()
  - quux = ?
    zip()
    - var quux

Once you spot the difference you can update your solution and try again :)

edrickchu commented 9 years ago

Wooo! Got it :)

Seems like I just needed to keep var bar in the solution, though, I had the scope chain correct!

One more question, what do the \n and \t mean?

Thanks!!

jesstelford commented 9 years ago

You're welcome - really glad you're enjoying it!

what do the \n and \t mean?

  • \n means newline
  • \t means tab

but that's just for output display, it doesn't mean you necessarily need to have exactly one newline and exactly one tab, etc. The code is normalised before being compared against the expected output of other normalised code.

iyogeshjoshi commented 9 years ago

It doesn't worked for me. Here is my code

function foo() {
  var bar;
  quxx = 1;
  function zip() {
    var quux = 2;
  }
}

still it's clearing only 1/2 test

# (anonymous)
ok 1 Solution loaded
not ok 2 The structure is correct
  ---
    operator: equal
    expected:
      '(global)\n\tfoo()\n\t- var bar\n\t- quux = ?\n\t\tzip()\n\t\t- var quux'
    actual:
      '(global)\n\tfoo()\n\t- var bar\n\t- quxx = ?\n\t\tzip()\n\t\t- var quux'

I don't get it how expected is different from actual!

jesstelford commented 9 years ago

@iyogeshjoshi Looks like you've got a spelling mistake there - quxx instead of quux.

iyogeshjoshi commented 9 years ago

@jesstelford sorry my bad!

SomeoneWeird commented 9 years ago

:tada: