I tried this but it doesn’t work. I didn’t know embedded if statements existed until now so I’m unfamiliar with them.
function lookUpProfile(name, prop) {
// Only change code below this line
for (let i = 0; i < contacts.length; i++){
if (name == contacts[i].firstName){
if (contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
}
else{
return "No such property";
}
}
else return "No such contact";
}
// Only change code above this line
}
function lookUpProfile(name, prop) {
// Only change code below this line
for (let i = 0; i < contacts.length; i++) {
if (name == contacts[i].firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else {
return "No such property";
}
} else return "No such contact";
}
// Only change code above this line
}
and let’s think of this… right now, when i is 0, something is always returned.
Do I need to change the value of i in one of if’s? But far as I know that would break the loop. Do I need two loops?
Also I ran the code though the tool but I don’t know what the results mean. It says something about a global frame and lookUpProfile. But I don’t know what a global frame is.
I guess more experienced people than me will explain you about frames soon enough.
To get something useful from python tutor in this case you need to place there all your code from this task, not just some snippet.
I’ve looked at steps 5, 6 and 7, I don’t know what I’m supposed to be seeing.
The arrows points at the code in turn, but I know which parts of the code execute at what point. So I don’t know what this tool is telling me.
So, how do I do the below without stopping the loop. While also nesting my if statements?
If both are true, then return the “value” of that property.
And how do I not keep accessing just ‘Akira’? I’m really stuck because I thought the way I was doing it would access all firstNames’s, not just the first one.