Why is the result of the code undefined?
I could not understand because I do not think to do a mistake.
let day = ‘Saturday’;
let alarm;
let person = {
name:‘robot’,
age:20,
weekendAlarm: ‘No alarms needed’,
weekAlarm: ‘Alarm set to 7AM’
};
if(day === ‘Saturday’ || day === ‘Sunday’) {
let alarm = ‘weekendAlarm’;
} else {
let alarm = ‘weekAlarm’;
}
console.log(person[alarm]);
My Output is undefined.