I try to find the second solution.
With this code bellow, the console return: “TypeError: userObj.indexOf is not a function”.
let tableNames = ['Alan','Jeff','Sarah','Ryan'];
for (let i = 0; i < tableNames.length; i++) {
if (userObj.indexOf(tableNames[i]) < 0) {
return false;
}
return true;
}
First ,I don’t know if it’s possible to add a “if” condition in a for loop ?
Second, I would like get out of the “if” condition at the first time that indexOf = -1. Is it the case in my code ?
Maye be it’s not possible with this kind of itération (let i = 0; i < tableNames.length; i++), but if it’s possible I would like to know how. Could you please tell me what’s wrong ?
Sorry, I didn’t understand, I try to speak english/American but …
I replaced “indexOf” by “hasOwnProperty”.
function isEveryoneHere(userObj) {
// Only change code below this line
let tableNames = ['Alan','Jeff','Sarah','Ryan'];
for (let i = 0; i < tableNames.length; i++) {
if (userObj.hasOwnProperty(tableNames[i]) < 0) {
return false;
}
return true;
}
I tried with this code and I changed the index 1 of tableNames.
function isEveryoneHere(userObj) {
// Only change code below this line
let tableNames = ['Alan','bob','Sarah','Ryan'];
for (let i = 0; i < tableNames.length; i++) {
if (!userObj.hasOwnProperty(tableNames[i])) {
return false;
} else {
return true
}
}
// Only change code above this line
function isEveryoneHere(userObj) {
// Only change code below this line
let tableNames = ['Alan','Jeff','fds','Ryan'];
for (let i = 0; i < tableNames.length; i++) {
if (!userObj.hasOwnProperty(tableNames[i])) {
return false;
}
}
return true
I changed the index 2, console return “false” and when replaced by Sarah, the console return “true”.