And what are the names of the attributes in the object you passed along with it?
I have no clue what you’re doing but it looks a whole lot like those don’t match.
A very important consideration is whether it had the desired effect. Don’t rely on codecademy to judge whether it’s right. If it did not have the desired effect then you have a much stronger indication of that it really isn’t right because you put it to the test that matters.
Not sure if I quite understand your follow-up. The variable is 'biology', if I understand what you’re asking. The very first code block I posted is my code, and the second block is the given solution.
More likely, the variable’s name doesn’t include the $, typically for string interpolation there’ll be some kind of escape sequence followed by the name of the thing that is special
> this['${stuff}'] = 5 // yeah you can make a variable with that name
5
> stuff = 3 // but more likely it's this name
3
> `${stuff}`
'3'
And you are absolutely right. time for me to get myself a clue then.
Looking at that checkpoint (the condition for it to pass), codecademy is inspecting the structure of your code in a manner that I have nothing kind to say about. They’re not testing the effect of your code, they expect it to match this:
I was grepping in the source of the exercises but that’s not public.
Sometimes parts of it are copied to the workspace, but that’s not reliable or convenient.
In this case they do copy it there, so taken straight from the learning environment, from test/test.js: (you might have to press run it before the file becomes non-empty…)
console.log = function() {};
const assert = require('chai').assert;
const fs = require('fs');
const Structured = require('structured');
const code = fs.readFileSync('app.js', 'utf8');
describe('', function () {
it('', function() {
// test use of db.all()
let dbAllStruct = function() {
db.all();
}
assert.isOk(Structured.match(code, dbAllStruct), 'Did you use `db.all()` to find a row?');
let queryStruct = function() {
db.all($qry);
}
assert.isOk(Structured.match(code, queryStruct), "Did you pass a query to your `db.all()` call?");
let fnStruct = function() {
db.all($query, $cb);
}
let fnCallbacks = {
'$cb': function(cb) {
if (cb.type !== 'ArrowFunctionExpression') {
return { failure: 'Did you pass an arrow function callback to your `db.all()` call?' }
}
return true;
}
}
let fnFailureMessage = "Don't forget to pass a query argument and callback function to `db.all()`"
assert.isOk(Structured.match(code, fnStruct, { varCallbacks: fnCallbacks }), fnCallbacks.failure || fnFailureMessage);
let structure = function() {
db.all($query, ($errName, $rowsName) => {
console.log($rowsName);
});
};
let varCallbacks = {
'$query': function(query) {
if (!query.value) {
return { failure: 'Did you pass a query string to `db.all()`?' }
}
const queryMatch = query.value.match(/SELECT\s*([\s\S]+?)\s+FROM\s+Scientist\s+WHERE\s+field\s*=\s*('|")biology('|")/i);
if (!queryMatch) {
return { failure: 'Did you use use a query to select the rows with the `field` of "biology"?' }
} else {
let colName = queryMatch[1];
if (!colName.match(/\*/)) {
return { failure: 'Did you select all rows from the Scientist table using *?' }
}
}
return true;
}
}
let isMatch = Structured.match(code, structure, { varCallbacks: varCallbacks });
let failureMessage = varCallbacks.failure || "Did you pass the correct query into `db.all()` and log the result?";
assert.isOk(isMatch, failureMessage);
});
});