Commits

Anonymous committed 74fc810

$ python py/remove_answers.py

Comments (0)

Files changed (5)

core-javascript/javascript-exercises/class-exercises.js

+var something;
+
+TEST('class attributes', function()
+{
+    var point = {};
+    var Point = SimpleClass(point);
+
+    point.__init__ = function(x, y){
+        // Please write your answer here.
+    };
+
+    var pt = Point(3, 4);
+
+    assert( pt.x === 3 );
+    assert( pt.y === 4 );
+
+    // Please write your answer here.
+
+    assert( pt.__classname__ === 'Point' );
+
+});
+
+
+TEST('class methods', function()
+{
+    var actual;
+    var expect;
+
+    var person = {};
+    var Person = SimpleClass(person);
+
+    // Initialise a person to have a name and an age.
+    // Please write your answer here.
+
+
+    // Test that we can create a person.
+    var someone = Person('Bob', 26);
+    assert( someone.name === 'Bob' );
+    assert( someone.age === 26 );
+
+
+    // Add a greet method to the class prototype object.
+    person.greet = function(another){
+        // Please write your answer here.
+    };
+
+    // Test the greet method.
+    var tmp =  someone.greet('Alice');
+    assert( tmp = something );
+
+    // Add a goodbye method.
+    // Please write your answer here.
+
+    expect = "Goodbye, Alice. It was a pleasure to meet you.";
+    actual = someone.goodbye('Alice');
+    assert( actual === expect );
+
+    // A flaw in the design.
+    var someone_else = Person('Alice', 31);
+
+    // Figure out what we get.
+    expect = something;
+    actual = someone.greet(someone_else);
+    assert( actual === expect );
+});

core-javascript/javascript-exercises/create-exercises.js

     c.ccc = 3;
     assert( a.ccc === undefined );
     assert( b.ccc === undefined );
-
 });

core-javascript/javascript-exercises/function-exercises.js

+var something = null;
+
+TEST('return value', function()
+{
+    var fn_1 = function(){
+    };
+
+    assert( fn_1() === something );
+
+    var fn_2 = function(){
+        // Please write your answer here.
+    };
+
+    assert( fn_2() === 42 );
+});
+
+
+TEST('parameters', function()
+{
+    var something = null;
+
+    var fn = function(a, b, c){
+        // Please write your answer here.
+    };
+
+    assert( fn(1, 2, 3) === 2 );
+    assert( fn(4, 5, 6) === 5 );
+
+    assert( fn(7, 8) === something );
+
+    assert( fn(9, 10, 11, 12) === something );
+
+    assert( fn(13) === something );
+
+    assert( fn() === something );
+});
+
+
+TEST('arguments', function()
+{
+    var something = null;
+
+    // 1
+    var fn_1 = function(){
+        return arguments.length;
+    };
+
+    assert( fn_1() === 0 );
+    assert( fn_1(0) === something );
+    assert( fn_1(0, 0) === something );
+    assert( fn_1(0, 0, 0) === something );
+
+
+    // 2
+    var fn_2 = function(i){
+        return arguments[i];
+    };
+
+    assert( fn_2(0) === something );
+    assert( fn_2(1, 1, 2) === something );
+    assert( fn_2(2, 10, 11) === something );
+});

core-javascript/javascript-exercises/scope-exercises.js

+var something;
+
+TEST('read scope', function()
+{
+    var a;
+    a = 3;
+
+    // 1
+    var fn_1 = function(a){
+        return a;
+    };
+
+    assert( fn_1(42) === something );
+
+    // 2
+    var fn_2 = function(b){
+        return a;
+    };
+
+    assert( fn_2(42) === something );
+
+    // 3
+    var fn_3 = function(b){
+        var a = b - 10;
+        return a;
+    };
+
+    assert( fn_3(42) === something );
+});
+
+
+TEST('assign scope', function()
+{
+    var a;
+
+    // 1
+    var fn_1 = function(a){
+        a = 5;
+    };
+
+    a = 3;
+    fn_1(42);
+    assert( a === something );
+
+    // 2
+    var fn_2 = function(b){
+        a = 5;
+    };
+
+    a = 3;
+    fn_2(42);
+    assert( a === something );
+
+    // 3
+    var fn_3 = function(b){
+        var a = b;
+    };
+
+    a = 3;
+    fn_3(42);
+    assert( a === something );
+
+    // 4
+    var fn_4 = function(b){
+        a = b;
+    };
+
+    a = 3;
+    fn_4(42);
+    assert( a === something );
+});
+
+
+TEST('function body', function()
+{
+    var a;
+    var b;
+
+    var fn_1 = function(c){
+        // Please write your answer here.
+    };
+
+    a = 3;
+    b = fn_1(5);
+    assert( a === 5);
+    assert( b === 3 * 5 );
+
+});

core-javascript/py/remove_answers.py

         src = os.path.join(answers_dir, name)
         tgt = os.path.join(exercises_dir, name)
 
+        print name
         doit(src, tgt)