Object in Object Code passed idk why?

Hello world,
I have a few questions figure out how my code passed.

  1. Why didn’t I have to use a for in loop for this to work?

  2. Why didn’t I have to use quotation syntax on obj [name] in the if statement?

  3. Why did I have to use obj[name].visits to get the value of visits? When there is an object in an object do I need to use dot notation even after calling the key pair value?
    shouldn’t I simply be able to use obj[name]

Here is the challenge:
Given the customerData object below, write a function greetCustomer that takes in a similar object and a name. Given that name, return a greeting based on how many times that person has visited your establishment. Essentially, you will check the name given to your function against the names in the object given to your function.

const customerData = {
 'Joe': {
   visits: 1
 'Carol': {
   visits: 2
 'Howard': {
   visits: 3
 'Carrie': {
   visits: 4

function greetCustomer(customerData, name){
  const obj = customerData;
 let greeting = '';

    if (!obj[name]){
      greeting = 'Welcome! Is this your first time?';
      return greeting;
    else if (obj[name].visits === 1){
      greeting = 'Welcome back,' + ' ' + name +'! We\'re glad you liked us the first time!';
      return greeting;
    if ( obj[name].visits > 1 ) {
      greeting = 'Welcome back,' + ' ' + name + '! It\'s good to see a regular customer';
      return greeting;

// If the customer is not present in customerData:
//greetCustomer(customerData, 'Terrance');
//console.log(greetCustomer(customerData, 'Terrance'))// 'Welcome! Is this your first time?'

// If the customer has visited only once ('visits' value is 1):
//greetCustomer(customerData, 'Joe'); // 'Welcome back, Joe! We're glad you liked us the first time!'
//console.log(greetCustomer(customerData, 'Joe'));

// If the customer is a repeat customer: ('visits' value is greater than 1)
greetCustomer(customerData, 'Carol'); // 'Welcome back, Carol! It's good to see a regular customer'
//console.log(greetCustomer(customerData, 'Carol'));te code here

the name is one the object keys, so you can access the object property directly using the function parameter

1 Like

Are you saying since the name is in a parameter of the function I dont need to use the quotation marks here obj[name]?

Without name being declared or set as a key I am not clear how the function knows the name is the customers name and not the visits.

the variable name is declared as function parameter

and is assigned a value when the function is called