Why do i get ReferenceError : nom is not defined


#1

https://www.codecademy.com/fr/courses/javascript-beginner-fr-FR-wnz9l/0/5?curriculum_id=5355c2b7516bcbd912000008#

My code seems to be good because the editors says me it's okay to move on the next lesson.
After viewing the script of the other people on this forum, i can't figure it out...

Why do i get a ReferenceError: nom is not defined with this code ? thanks per advance ! :slight_smile:


Replace this line with your code. 

`var bob = {
    prenom: "Bob",
    nom: "Jones",
    telephone: "01 23 45 67 89",
    email: "bob.jones@exemple.com"
};

var mary = {
    prenom: "Mary",
    nom: "Johnson",
    telephone: "02 34 56 78 91",
    email: "mary.johnson@exemple.com"
};

var contacts = [bob, mary];

function affichePersonne(personne) {
    console.log(personne.prenom + " " + personne.nom);
};

function liste() {
	var longueurContacts = contacts.length;
	for (var i = 0; i < longueurContacts; i++) {
		affichePersonne(contacts[i]);
	}
}

function recherche (nom) {
    var longueurContacts = contacts.length; 
    for (var i = 0; i < longueurContacts; i++) {
        console.log(contacts[i].nom);
    	if (contacts[i].nom === nom) {
    	    affichePersonne(contacts[i]);
    	} else {
    	    console.log("aucun contact trouvé avec le nom" + " " + nom);
    	}
    }
};

nom ("Jones");`


#2

nom ("Jones");

guess you wanted to call:

recherche("Jones");


#3

oh i'm an idiot, thank you very much !


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.