I am trying to make the function in this code run a different greeting based upon the value of each customer's 'visits'. I keep getting an error that says "Cannot read property 'visits' of undefined."
What am I missing here?
var customerData = {
'Joe': {
visits: 1
},
'Carol': {
visits: 2
},
'Howard': {
visits: 3,
},
'Carrie': {
visits: 4
}
};
function greetCustomer(firstName) {
var greeting = '';
if(customerData.firstName.visits === 1){
greeting = "Welcome back, " + firstname +"!" + " We're glad you liked us the first time!";
}
else if(customerData.firstName.visits > 1){
greeting = "Welcome back, " + firstname +"!" + " So glad to see you again!";
}
else{
greeting = "Welcome! Is this your first time?";
}
return greeting;
}
greetCustomer("Carrie");