- Posts: 1
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<!DOCTYPE html> <html> <body> <script src="https://wzrd.in/standalone/tape@latest"></script> <script src="https://wzrd.in/standalone/tap-browser-color@latest"> </script> <script src="https://wzrd.in/standalone/deep-freeze@latest"></script> <script> window.test = tape; tapBrowserColor(); </script> </body> </html> <script> const users = [ { "login": "knuth", "firstName": "Donald", "lastName": "Knuth", "likes": ["C", "Unix"] }, { "login": "norvig", "firstName": "Peter", "lastName": "Norvig", "likes": ["AI", "Search", "NASA", "Mars"] }, { "login": "mfowler", "firstName": "Martin", "lastName": "Fowler", "likes": ["Design Patterns", "Refactoring"] }, { "login": "kent", "firstName": "Kent", "lastName": "Beck", "likes": ["TDD", "wikis", "Design Patterns"] } ]; // lookup() const lookup = (login, prop) => { // Only change code below this line const found = users.find(function(e){ return e.login === login; }); if(!found) { throw "Could not find user"; } else { if(prop in found) { return found[prop]; } else { throw "Could not find property"; } } }; // lookupAsync() const lookupAsync = (login, prop, callback) => { // Only change code below this line const found = users.find(function(e){ return e.login === login; }); if(!found) { throw "Could not find user"; } else { if(prop in found) { return found[prop]; } else { throw "Could not find property"; } } //my intension below but doesn't work //callback(); //lookupAsync(function (err,res) {}); }; test('lookupAsync() likes', assert => { const msg = `lookupAsync(<login>, 'likes', callback) should return likes for the specified user.`; lookupAsync('norvig', 'likes', function(err, res){ const actual = res; const expected = ["AI", "Search", "NASA", "Mars"]; assert.deepEqual(actual, expected, msg); assert.end(); }); }); test('lookupAsync() last name', assert => { const msg = `lookupAsync(<login>, 'lastName') should return the last name for the specified user.`; lookupAsync('knuth', 'lastName', function(err, res){ const expected = 'Knuth'; const actual = res; assert.deepEqual(actual, expected, msg); assert.end(); }); }); test('lookupAsync() with unknown user', assert => { const msg = `lookupAsync() with unknown user should return an error with the correct message.`; const value = lookupAsync('nobody', 'likes', function(err, res){ const actual = err.message; const expected = 'Could not find user.'; assert.equal(actual, expected, msg); assert.end(); }); }); test('lookupAsync() with unknown property', assert => { const msg = `lookupAsync() with unknown property should return an error with the correct message`; lookupAsync('mfowler', 'noprop', function(err, res){ const actual = err.message; const expected = 'Could not find property.'; assert.equal(actual, expected, msg); assert.end(); }); }); </script>