What's new

Help -- SOLVED --

Status
Not open for further replies.

fuzzywubby

Elite
Joined
Sep 20, 2018
Posts
5,123
Solutions
2
Reaction
3,035
Good Day!

Pahelp naman po kung paano gagawin dito. Gumagana naman po lahat ng condition, ang problema nalang is di ko makuha etong nakahighlight. Hindi ko sya ma-explain ng maayos haha
Problem:
1663903831338.png


Expected Output:

1663904000440.png


Code:
JavaScript:
//New User Data:
let names = ['Jane Manalo', 'Alexis Crisostomo', 'Kris Aquino', 'Ashley Mendoza', 'Louise Sotto', 'Taylor Santos', 'Sarah Geronimo', 'Kate Panganiban', 'Jack Cuenca', 'Mike Enriquez', 'Kim Dora', 'Ruben Tulfo', 'Anthony Davis', 'Sony Station', 'Poly Gon'];
let namesGender = ['Female', 'Male', 'Male', 'Female', 'Female', 'Female', 'Female', 'Female', 'Male', 'Male', 'Male', 'Male', 'Male', 'Male', 'Female'];
let namesAddress = ['Antipolo', 'Tanay', 'Teresa', 'Morong', 'Tanay', 'Antipolo', 'Teresa', 'Taytay', 'Angono', 'Taytay', 'Binangonan', 'Baras', 'Cardona', 'Pinugay', 'Cogeo'];
let namesContact = ['09153256598', '09853254578', '095583232652', '09885323535', '0983265682', '09125786234', '09532558633', '09115863296', '0999856332', '098885632222', '09663236332', '09874747852', '09885231553', '09663225466', '09111111111'];

// Existing User Database:
let existingNames = ['Jay Manalo', 'Alexis Crisostomo', 'Kris Aquino', 'Ashley Mendoza', 'Louis Sotto', 'Taylor Santos', 'Sarah Geronimo', 'Kaye Panganiban', 'Jake Cuenca', 'Mike Enriquez', 'Kim Dora', 'Ben Tulfo', 'Anthony Davis', 'Sony Station', 'Joly Gon'];
let existingNamesGender = ['Male', 'Female', 'Female', 'Female', 'Female', 'Female', 'Female', 'Female', 'Male', 'Male', 'Female', 'Male', 'Male', 'Male', 'Male'];
let existingNamesAddress = ['Antipolo', 'Tanay', 'Teresa', 'Cardona', 'Tanay', 'Antipolo', 'Teresa', 'Angono', 'Angono', 'Morong', 'Binangonan', 'Baras', 'Cainta', 'Pinugay', 'Sampaloc'];
let existingNamesContact = ['09115863296', '09552228888', '09575757575', '09252525252', '09444444444', '09125786234', '09532558632', '09853254578', '09333333333', '09222222222', '09666666666', '09777777777', '09698989898', '09563221111', '09111111111'];

let successCount = [];


for (let i = 0; i < names.length; i++) {
    if (namesContact[i].length > 11) {
        console.log(names[i] + " user registration FAILED!\nAll data presented is unique but the Contact Number is invalid.\nContact Number is more than 11 digits!\nAdding to the Database Failed.")
    }
    else if (namesContact[i].length < 11) {
        console.log(names[i] + " user registration FAILED!\nAll data presented is unique but the Contact Number is invalid.\nContact Number is less than 11 digits!\nAdding to the Database Failed.")
    } else if (names.includes(existingNames[i]) && namesAddress.includes(existingNamesAddress[i]) && namesContact.includes(existingNamesContact[i])) {
        console.log(names[i] + " user registration FAILED!\nAll of the Users Data is already in Existing User Database.\nAdding to the Database Failed.")
    } else if (existingNamesContact.includes(namesContact[i])) {
        console.log(names[i] + " user registration FAILED!\nAll data presented is unique except for the Contact Number.\nContact Number already exist to " + /* PANGALAN DITO NG MAY SAME NUMBER */ +"\nAdding to the Database Failed.")
    } else if (names[i] == existingNames[i] && namesGender[i] == existingNamesGender[i] && namesAddress[i] == existingNamesAddress[i]) {

        console.log(names[i] + " user registration FAILED!\nAll of the Users Data is already Existing except Contact Number.\nAdding to the Database Failed.")
    } else {
        console.log(names[i] + " user registration SUCCESS!\nAll data presented is unique and valid.\nDone Adding to the Database.")
        successCount.push(names[i]);
    }
}
console.log("We have a total of " + successCount.length + " new User Data added to the Database, they are " + successCount.join(', '));

Output na nagawa ko:
1663903938587.png


Sana po nagets nyo haha. TIA!
 

Attachments

PHC_Jayvee

nakatapos din sa research😂🤣
Contributor
Assuming na by index match yung person at number


Code:
const index = existingNamesContact.indexOf(numberNungBagongPerson)


if(index === -1) goods to not use

if(index >= 0) {
may same number
const matchName = existingNames[index]
}
 
Assuming na by index match yung person at number


Code:
const index = existingNamesContact.indexOf(numberNungBagongPerson)


if(index === -1) goods to not use

if(index >= 0) {
may same number
const matchName = existingNames[index]
}
Baka pwede pa elaborate pa po, medyo naguluhan lang 😅
 

dmartinez_01

Established
First get the array index position of existing contact number
Then the return index will use as an argument to target the contact holder of that number.

Eto ung complete code. sana makatulong. Or you may see my sample jsfiddle on this link:
https:// jsfiddle.net/dmartinez01/kz94fenx/


//New User Data:
let names = ['Jane Manalo', 'Alexis Crisostomo', 'Kris Aquino', 'Ashley Mendoza', 'Louise Sotto', 'Taylor Santos', 'Sarah Geronimo', 'Kate Panganiban', 'Jack Cuenca', 'Mike Enriquez', 'Kim Dora', 'Ruben Tulfo', 'Anthony Davis', 'Sony Station', 'Poly Gon'];

let namesGender = ['Female', 'Male', 'Male', 'Female', 'Female', 'Female', 'Female', 'Female', 'Male', 'Male', 'Male', 'Male', 'Male', 'Male', 'Female'];

let namesAddress = ['Antipolo', 'Tanay', 'Teresa', 'Morong', 'Tanay', 'Antipolo', 'Teresa', 'Taytay', 'Angono', 'Taytay', 'Binangonan', 'Baras', 'Cardona', 'Pinugay', 'Cogeo'];

let namesContact = ['09153256598', '09853254578', '095583232652', '09885323535', '0983265682', '09125786234', '09532558633', '09115863296', '0999856332', '098885632222', '09663236332', '09874747852', '09885231553', '09663225466', '09111111111'];

// Existing User Database:
let existingNames = ['Jay Manalo', 'Alexis Crisostomo', 'Kris Aquino', 'Ashley Mendoza', 'Louis Sotto', 'Taylor Santos', 'Sarah Geronimo', 'Kaye Panganiban', 'Jake Cuenca', 'Mike Enriquez', 'Kim Dora', 'Ben Tulfo', 'Anthony Davis', 'Sony Station', 'Joly Gon'];

let existingNamesGender = ['Male', 'Female', 'Female', 'Female', 'Female', 'Female', 'Female', 'Female', 'Male', 'Male', 'Female', 'Male', 'Male', 'Male', 'Male'];

let existingNamesAddress = ['Antipolo', 'Tanay', 'Teresa', 'Cardona', 'Tanay', 'Antipolo', 'Teresa', 'Angono', 'Angono', 'Morong', 'Binangonan', 'Baras', 'Cainta', 'Pinugay', 'Sampaloc'];

let existingNamesContact = ['09115863296', '09552228888', '09575757575', '09252525252', '09444444444', '09125786234', '09532558632', '09853254578', '09333333333', '09222222222', '09666666666', '09777777777', '09698989898', '09563221111', '09111111111'];

let successCount = [];

function findKey(object, value)
{
var keyArr=[];
for (let key in object)
{
if (object[key] === value)
{
keyArr.push(key);
}
}
if(keyArr.length >0 )
{
return keyArr;
}
else
{
return "Not Found";
}
}


for (let i = 0; i < names.length; i++) {

if (namesContact.length > 11) {
console.log(names + " user registration FAILED!\nAll data presented is unique but the Contact Number is invalid.\nContact Number is more than 11 digits!\nAdding to the Database Failed.")
}

else if (namesContact.length < 11) {

console.log(names + " user registration FAILED!\nAll data presented is unique but the Contact Number is invalid.\nContact Number is less than 11 digits!\nAdding to the Database Failed.")

} else if (names.includes(existingNames) && namesAddress.includes(existingNamesAddress) && namesContact.includes(existingNamesContact)) {

console.log(names + " user registration FAILED!\nAll of the Users Data is already in Existing User Database.\nAdding to the Database Failed.")

} else if (existingNamesContact.includes(namesContact)) {

console.log(names + " user registration FAILED!\nAll data presented is unique except for the Contact Number.\nContact Number already exist to " + /* PANGALAN DITO NG MAY SAME NUMBER */ existingNames[findKey(existingNamesContact, namesContact)] +"\nAdding to the Database Failed.")

} else if (names == existingNames && namesGender == existingNamesGender && namesAddress == existingNamesAddress) {

console.log(names + " user registration FAILED!\nAll of the Users Data is already Existing except Contact Number.\nAdding to the Database Failed.")

} else {

console.log(names + " user registration SUCCESS!\nAll data presented is unique and valid.\nDone Adding to the Database.")
successCount.push(names);
}

}

console.log("We have a total of " + successCount.length + " new User Data added to the Database, they are " + successCount.join(', '));
 
Last edited:
First get the array index position of existing contact number
Then the return index will use as an argument to target the contact holder of that number.

Eto ung complete code. sana makatulong. Or you may see my sample jsfiddle on this link:
https:// jsfiddle.net/dmartinez01/kz94fenx/


//New User Data:
let names = ['Jane Manalo', 'Alexis Crisostomo', 'Kris Aquino', 'Ashley Mendoza', 'Louise Sotto', 'Taylor Santos', 'Sarah Geronimo', 'Kate Panganiban', 'Jack Cuenca', 'Mike Enriquez', 'Kim Dora', 'Ruben Tulfo', 'Anthony Davis', 'Sony Station', 'Poly Gon'];

let namesGender = ['Female', 'Male', 'Male', 'Female', 'Female', 'Female', 'Female', 'Female', 'Male', 'Male', 'Male', 'Male', 'Male', 'Male', 'Female'];

let namesAddress = ['Antipolo', 'Tanay', 'Teresa', 'Morong', 'Tanay', 'Antipolo', 'Teresa', 'Taytay', 'Angono', 'Taytay', 'Binangonan', 'Baras', 'Cardona', 'Pinugay', 'Cogeo'];

let namesContact = ['09153256598', '09853254578', '095583232652', '09885323535', '0983265682', '09125786234', '09532558633', '09115863296', '0999856332', '098885632222', '09663236332', '09874747852', '09885231553', '09663225466', '09111111111'];

// Existing User Database:
let existingNames = ['Jay Manalo', 'Alexis Crisostomo', 'Kris Aquino', 'Ashley Mendoza', 'Louis Sotto', 'Taylor Santos', 'Sarah Geronimo', 'Kaye Panganiban', 'Jake Cuenca', 'Mike Enriquez', 'Kim Dora', 'Ben Tulfo', 'Anthony Davis', 'Sony Station', 'Joly Gon'];

let existingNamesGender = ['Male', 'Female', 'Female', 'Female', 'Female', 'Female', 'Female', 'Female', 'Male', 'Male', 'Female', 'Male', 'Male', 'Male', 'Male'];

let existingNamesAddress = ['Antipolo', 'Tanay', 'Teresa', 'Cardona', 'Tanay', 'Antipolo', 'Teresa', 'Angono', 'Angono', 'Morong', 'Binangonan', 'Baras', 'Cainta', 'Pinugay', 'Sampaloc'];

let existingNamesContact = ['09115863296', '09552228888', '09575757575', '09252525252', '09444444444', '09125786234', '09532558632', '09853254578', '09333333333', '09222222222', '09666666666', '09777777777', '09698989898', '09563221111', '09111111111'];

let successCount = [];

function findKey(object, value)
{
var keyArr=[];
for (let key in object)
{
if (object[key] === value)
{
keyArr.push(key);
}
}
if(keyArr.length >0 )
{
return keyArr;
}
else
{
return "Not Found";
}
}


for (let i = 0; i < names.length; i++) {

if (namesContact.length > 11) {
console.log(names + " user registration FAILED!\nAll data presented is unique but the Contact Number is invalid.\nContact Number is more than 11 digits!\nAdding to the Database Failed.")
}

else if (namesContact.length < 11) {

console.log(names + " user registration FAILED!\nAll data presented is unique but the Contact Number is invalid.\nContact Number is less than 11 digits!\nAdding to the Database Failed.")

} else if (names.includes(existingNames) && namesAddress.includes(existingNamesAddress) && namesContact.includes(existingNamesContact)) {

console.log(names + " user registration FAILED!\nAll of the Users Data is already in Existing User Database.\nAdding to the Database Failed.")

} else if (existingNamesContact.includes(namesContact)) {

console.log(names + " user registration FAILED!\nAll data presented is unique except for the Contact Number.\nContact Number already exist to " + /* PANGALAN DITO NG MAY SAME NUMBER */ existingNames[findKey(existingNamesContact, namesContact)] +"\nAdding to the Database Failed.")

} else if (names == existingNames && namesGender == existingNamesGender && namesAddress == existingNamesAddress) {

console.log(names + " user registration FAILED!\nAll of the Users Data is already Existing except Contact Number.\nAdding to the Database Failed.")

} else {

console.log(names + " user registration SUCCESS!\nAll data presented is unique and valid.\nDone Adding to the Database.")
successCount.push(names);
}

}

console.log("We have a total of " + successCount.length + " new User Data added to the Database, they are " + successCount.join(', '));
Thank youuuuu!!!
 
Status
Not open for further replies.
Top