Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!-- User constructor -->
<script src="http://output.jsbin.com/fasebo.js"></script>
<!-- fitnessApp.userView -->
<script src="http://output.jsbin.com/yapahe.js"></script>
 
// Get Programming with JavaScript
// Listing 16.01
// The fitness app controller
(function () {
  
  var buildUser = function (userData) {
    var user = new fitnessApp.User(userData.name);
  
    userData.sessions.forEach(function (session) {
      user.addSession(session.sessionDate, session.duration);
    });
  
    return user;
  };
  
  var init = function (userData) {
    var user = buildUser(userData);
    
    fitnessApp.userView.render(user);
    
    return {
      log: function (sessionDate, duration) {
        user.addSession(sessionDate, duration);
        fitnessApp.userView.render(user);
        return "Thanks for logging your session.";
      }
    };
  };
  
  if (window.fitnessApp === undefined) {
    window.fitnessApp = {};
  }
  
  fitnessApp.init = init;
  
})();
/* Further Adventures
 *
 * The User constructor and user view
 * code have been imported on the
 * HTML panel.
 *
 * The user data needs a name and
 * a sessions array.
 *
 * 1) Run the program.
 *
 * 2) At the console, create some
 *    user data:
 *
 *    > var data = { name: 'Bob', sessions: [] }
 *
 * 3) Initialize the fitness app
 *    with the data:
 *
 *    > var user = fitnessApp.init(data)
 *
 * 4) Log a session:
 *
 *    > user.log("2016-09-03", 40)
 *
 */
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
jrlarsenpro
0viewers