1

I'm a fairly new student in AP CSP, and I wanted to create a username/password system in code.org's App Lab, however, it requires me to get the readRecords() command to function first.

I have the code as such :

function read (array) {
  var truth;
  readRecords("loginarray", {}, function(records) {
    if (records.length > 0) {
      for (var i = 0; i < records.length; i++){
        if (array.user == records[i].user){
          if (array.pass == records[i].pass) {
            truth = false;
            hideElement("unverifiedtext");
            hideElement("retrybutton");
            setScreen("verifyscreen");
          }
        }
      }
    }
  }
  );
  return truth;
}

But nothing I do seems to get the readRecords() command working. I'm rather confused, can this asynchronous timing be meddled with at all? If not, how should I go about fixing this issue?

Thanks in advance!

  • It would be helpful to see the code that is calling `read()`. I see a couple of potential problems here. One is that your function always returns `undefined` so if you are depending on its return value that might be the problem. Another is that you're passing an argument called `array` but treating it as an object, not an array, so clarity around what the shape of your argument is would help. – Brad Buchanan Mar 11 '19 at 21:24
  • Either way, please check out the readRecords() docs, and especially the syntax for filtering the results you get back, e.g. `readRecords("loginarray", {user: array.user}, function(records) { ...`. (https://docs.code.org/applab/readRecords/) – Brad Buchanan Mar 11 '19 at 21:25

0 Answers0