Please can someone tell me why this only works when a duplicate email address is entered

import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
import {session} from ‘wix-storage’;

$w.onReady( function () {
let newName = session.getItem(“newName2”)
$w(“#text10”).text = newName
})

export function input1_viewportEnter(event) {
$w(“#input1”).focus()
}

export function button1_click(event) {
session.setItem(“duplicateEmailAddress”,“No”);
$w(“#text13”).hide();
var newEmailAddress = $w(“#input1”).value
if (newEmailAddress === “”) {
$w(“#text13”).text = “Please enter your email address”
$w(“#text13”).show();
return ;
}
wixData.query(“User-Accounts-Practice-3”)
.find()
.then((results => {
let items = results.items;
let totalCount = results.totalCount;
for ( let i = 0;i <= totalCount;i++) {
let currentAddressBeingChecked = (items[i].emailAddress)
if (currentAddressBeingChecked === newEmailAddress) {
$w(“#text13”).text = “An account with this email address already exists”;
$w(“#text13”).show();
session.setItem(“duplicateEmailAddress”,“Yes”);
console.log(session.getItem(“duplicateEmailAddress”));
break
}
}
console.log(“WHY DO I NEVER SEE THIS UNLESS THE EMAIL ADDRESS ENTERED IS A DUPLICATE? - IF THE ADDRESS IS DUPLICATE I DO SEE IT”)
seeIfDuplicateAddress()
}))
}
function seeIfDuplicateAddress() {
let abc = session.getItem(“duplicateEmailAddress”);
console.log(abc);
if (abc === “No”) {
console.log(“ADDRESS IS NOT A DUPLICATE - N.B. I NEVER SEE THIS”);
}
else
{
console.log(“ADDRESS IS A DUPLICATE”)
}
}

export function page1_click(event) {
$w(“#input1”).focus()
}

Before the following line:

  if (currentAddressBeingChecked === newEmailAddress) { 

you could insert the following code:

 console.log("currentAddressBeingChecked  =" + currentAddressBeingChecked);
 console.log("newEmailAddress =" + newEmailAddress);
 console.log("currentAddressBeingChecked === newEmailAddress =" + currentAddressBeingChecked === newEmailAddress);

That might yield insights that could help answer your question.

Thank you for this suggestion. I tried it and everything is working correctly with regards to checking the email addresses in the loop. The code after the loop simply does not execute unless the loop finds a duplicate email address. has found a duplicate ew