Hey guys, so bascially we are making a website that randomly allows strangers to match up (duos or squads) and then displays their matches on the screen. We wrote some code for the match making part of the website, however, it does not display the matches. We think the problem is the “people” variable because every time the page is opened by a new user, a new instance is created (and we think this is what is happening not sure). Thanks in advance!!
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function () {
var people = [];
$w('#button6').onClick((event) =>
{
wixData.query("Members/PrivateMembersData")
.eq("_id", wixUsers.currentUser.id)
.find()
.then((results) => {
var first = results.items[0].firstName;
var last = results.items[0].lastName;
var team = makeTeam(first, last);
if (team.length === 2){
displayTeam(team);
people.slice(0, 2);
}
else{
$w("#text1").text = "Not enough people online to form team :(";
$w("#text2").text = "Member 1";
$w("#text3").text = "Member 2";
}
} )
});
function makeTeam(first, last){
people.push([first, last]);
return people;
}
function displayTeam(team){
$w("#text1").text = "Your team is: ";
$w("#text2").text = team[0][0] + ' ' + team[0][1];
$w("#text3").text = team[1][0] + ' ' + team[1][1];
}
});