Javascript: Objects 6/15


#1

I’m stuck at the OBJECTS: Adding a Property section of the Javascript lessons.

Codecademy logs the second instruction as incorrect, however the code itself outputs the desired results. The exercise insists that the code is incorrect.

let day = 'Tuesday';
let alarm;
const person = {
    name: 'Chris',
    age: 26,
    weekendAlarm: 'No alarms needed',
    weekAlarm: 'Alarm set to 7am',
  };

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

person.hobbies = ['Exercise', 'Coding'];
console.log(person['name']);
console.log(person['age']);
console.log(person[alarm]);
console.log (person.hobbies);

#2

I’m confused. Where did this line come from, and what purpose does it serve?


#3

it’s requested as part of the first instruction to add a ‘hobbies’ property using dot notation, second instruction is to log the information onto the console. It log’s just fine however the exercise does not consider that method to be correct.


#4

Without doing the whole unit over again, it’s hard to say what’s wrong. My code has this,

person['weekendAlarm'] = 'No alarms needed';
person['weekAlarm'] = 'Alarm set to 7AM';

instead of writing directly into the object.


#5

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