Test results

    The code with function properties

        
       <script type="text/javascript">
        
                var ninja = {
                    
                            attack:function(steps) {
                            
                                // any history array
                                if (ninja.attack.history == undefined) {
                                    // create one
                                    ninja.attack.history = new Array();
                                }
                                
                                // save steps
                                ninja.attack.history.push(steps);
                            
                                // return object
                                var result = { 'type': 'katana', 'points': 0 };
                               
                                // any step?
                                if (steps != undefined) {
                                    
                                    // calculate damage
                                    var dmg = Math.floor( Math.random() * 10 * steps );
                                    
                                    // save and return
                                   result.points = dmg;
                                   return result;
                                    
                                } else {
                                
                                    // no step taken    
                                    result.points = 1;
                                    return result;
                                
                                }
                                
                            }
            };
            
            /* test 1; no history? */
            assert( ninja.attack.history==undefined , "ninja.attack.history is not defined" );
           
            /* test 2; call attack 3 times and then get history */
            ninja.attack(2);
            ninja.attack(1);
            ninja.attack(3);
           
            assert( ninja.attack.history.length>0 , "ninja.attack.history has saved items (history contents: "+ninja.attack.history.toString()+")" )
            
       </script>