Update index.js

Issue with scope and error handling.
diff --git a/tree/index.js b/tree/index.js
index ed62c89..c2d50f8 100755
--- a/tree/index.js
+++ b/tree/index.js
@@ -71,6 +71,7 @@
 
         while (root.type !== "result") {
             var attr = root.name;
+            var child_node;
             if (root.type === 'feature_real') {
                 var sample_value = parseFloat(sample[attr]);
                 if (sample_value <= root.cut){
@@ -80,15 +81,18 @@
                 }
             } else {
                 var sample_value = sample[attr];
-                var child_node = _.detect(root.vals, function(x) {
+                child_node = _.detect(root.vals, function(x) {
                     return x.name == sample_value;
                 });
             }
-            root = child_node.child;
+            if (child_node) {
+               root = child_node.child;
+            }
+            break;
         }
 
         return root.val;
     }
 };
 
-module.exports = DecisionTreeClassifier;
\ No newline at end of file
+module.exports = DecisionTreeClassifier;