• I've stumbled across a problem that I can't get my head around and am not sure what to search for to learn how to resolve it. Can anyone help name a technique or method which I can read up on?

    I'm trying to access a propety of an object which changes depending on the output of a function. This is a simplified example:

    var days = {
      Monday: {hour: 6, minute: 30},
      Tuesday: {hour: 7, minute: 0},
    };
    
    var today = function() {
      return "Tuesday" // simplified for this example - not sure if return is best approach
    };
    
    console.log(days[today].hour);
    

    Espruino says:

    Uncaught Error: Cannot read property 'hour' of undefined
     at line 1 col 24
    console.log(days[today].hour);
                           ^
    

    Do I need to get today to return a string instead? Any help would be much appreciated.

    This is a situation where I don't know enough to help myself :)

About

Avatar for user101594 @user101594 started