scope-chains-closures icon indicating copy to clipboard operation
scope-chains-closures copied to clipboard

Unable to complete Closures exercise

Open ryoboua opened this issue 7 years ago • 3 comments

My code is:

function foo(){ var bar; function zip() { bar = true; } return zip; }

It fails with:

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

ryoboua avatar Apr 21 '17 19:04 ryoboua

Hey @ryoboua , I assume this is for exercise 4?

I believe you need to carry over the quux variables from the previous exercise. This solution worked for me. What you've written is correct though for the focus of the exercise

function foo() {
	var bar;
	quux = true;

	function zip() {
		bar = true;	
		var quux = false;	
	}
	return zip;
}

NolanChan avatar Apr 28 '17 01:04 NolanChan

It's always failed for me.

function foo() {
  var bar;
  quux = "quux";

  function zip () {
    var quux = "quux-zip";
    bar = true;
  }

  return zip;
}

@NolanChan, your solution doesn't get passed too.

chamnap avatar Jun 19 '17 03:06 chamnap

you need to keep the var bar , so that give

function foo() {
        var bar
        function zip() {
                var quux  
        }
}

note that this weird thing also work lol

function foo() {
        var bar = function zip() {
                var quux
        }
}

Sceat avatar Jun 18 '18 21:06 Sceat