Alex
Alex

Reputation: 3

Why aren't i successfully getting the embedded "if" in the second code section to do its job?

var checking_location = "none"

const getentitiesByType = (arr, type) => {
  for (let i in arr) {
    if (arr[i].type === type) {


      checking_location = "exists"
      return arr[i].entity
    }
  }
  return null;
}
if (!meeting.location) {
  if (checking_location != 'exists') {
    rl.question('where is the location ', function(answer) {
      // session.send("The location you gave:" answer);
      rl.close();
      session.send(answer)
        // console.log(tryagain(answer, 'Calendar.Location'));
      session.send(tryagain(answer, 'Calendar.Location'));
    });
  }
} else {
  next();
}

What i'm trying to do here is to have a loop in the if (!meeting.location) if checking_location stays equal to none. Basically i want to check if a certain Json field exists, if it doesn't i want to keep asking the question in rl.question.My issues is that the code is only working the first time, then even if i give another input not containing the required field i don't get that question.Also note that this is not the entire code but it's more than enough to understand the possible issue spots in my implementation.

Upvotes: 0

Views: 61

Answers (1)

BrotherDonkey
BrotherDonkey

Reputation: 183

getentitiesByType needs to be called somewhere, simply assigning it to a variable will not make the function run: getentitiesByType(youArr, yourType).

Also, as a side note, instead of using string values for checking_location just rename the variable and use a boolean value. Ex: var hasLocation = false.

Upvotes: 1

Related Questions