Here's my code:
Runs pretty darn good.
But let introduce "let" before the alarm variable in the if/else loops
I run the code
and boom error?
But why tho? Why shouldn't I use 'let' to introduce my variables in the if/else parts?
Code:
let person = {
name: 'Tyron',
age: 40,
weekendAlarm: 'No alarms needed',
weekAlarm: 'Alarm set to 7AM'
};
console.log(person['name']);
console.log(person['age']);
let day = 'Tuesday';
if (day === 'Saturday' || day === 'Sunday' ) {
alarm = 'weekendAlarm';
} else {
alarm = 'weekAlarm';
}
console.log(person[alarm]);
But let introduce "let" before the alarm variable in the if/else loops
Code:
let person = {
name: 'Tyron',
age: 40,
weekendAlarm: 'No alarms needed',
weekAlarm: 'Alarm set to 7AM'
};
console.log(person['name']);
console.log(person['age']);
let day = 'Tuesday';
if (day === 'Saturday' || day === 'Sunday' ) {
let alarm = 'weekendAlarm';
} else {
let alarm = 'weekAlarm';
}
console.log(person[alarm]);
I run the code
and boom error?
But why tho? Why shouldn't I use 'let' to introduce my variables in the if/else parts?
Comment