Learn JavaScript: Objects 5/15


#1
let day = "Friday";
let alarm;

let person = {
  name: 'Tyron',
  age: 40, 
  weekendAlarm: "No alarms needed",
  weekAlarm: "Alarm set to 7AM"
};

console.log(person["name"]);
console.log(person["age"]);

if(day === 'Saturday' || day === 'Sunday') {
    alarm = person["weekendAlarm"];
}
else {
  alarm = person["weekAlarm"];
}

console.log(alarm)

My code get’s an error at step 3 “Did you write an if condition that checks if the day is Saturday, or is Sunday and if so, sets the alarm variable to ‘weekendAlarm’?”

Nevermind. I found that you can get the solution. I am not stuck anymore.


#2

but getting the solution prevents you from learning something critical, which is trying to understand error message and attempting to solve them.


#3

The problem was I didn’t realize the test suite wanted a string called “weekendAlarm” & “weekAlarm” instead of putting in the logical answer which is pointing to the actual person.weekendAlarm itself.

The hint doesn’t mention the answer should be a string instead of the actual object itself.


#4

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