var clothesAreClean = true;
var coalbin = [];
var mountain = ['o','o','o','o','o','o','o','o','o','o','o','o','o','o']; // <== pieces of coal!
var amountOfCoal = 0;
var coalScoopCapacity = 3;

var startmining = function() {
  while(mountainHasCoal()) {
    if(haveCleanClothes()) {
      doSomeMining();
    } else {
      console.log("Need to wash clothes!");
      washClothes();
    }
  }
};

var mountainHasCoal = function() {
  return !!mountain.length;
};

var haveCleanClothes = function() {
  return clothesAreClean;
};

var doSomeMining = function() {
  amountOfCoal = Math.ceil(Math.random()*coalScoopCapacity);
  for(var i=0; i<amountOfCoal; i++) {
    var coal = mountain.pop();
    coalbin.push(coal);
  }
};

var washClothes = function() {
  if(coalbin.pop()) {
    clothesAreClean = true;
  } else {
    // oh, no, we don't have enough coal to run the washer!
    throw new Error("Washing Machine Error: code 729, insufficient power");  
    // ^^^ this is a joke; don't write confusing error messages like this
  }
  return true; 
};

startmining();
console.log("I mined "+coalbin.length+" pieces of coal from that bad ol' mountain!");

@@ -25,26 +25,8 @@
 ue;%0A
-var coalbin = %5B%5D;%0A
 var 
@@ -199,16 +199,56 @@
 ion() %7B%0A
+  var coalbin = %5B%5D;%0A  var theCoal = %5B%5D;%0A
   while(
@@ -302,16 +302,26 @@
  %7B%0A     
+ theCoal =
  doSomeM
@@ -325,24 +325,140 @@
 meMining();%0A
+      for(var i = 0; i%3CtheCoal.length; i++)%0A      %7B%0A          coalbin.push(theCoal%5Bi%5D);%0A      %7D%0A      theCoal = %5B%5D;%0A
     %7D else %7B
@@ -507,16 +507,26 @@
 );%0A     
+ coalbin =
  washClo
@@ -530,16 +530,23 @@
 Clothes(
+coalbin
 );%0A    %7D
@@ -546,24 +546,49 @@
 ;%0A    %7D%0A  %7D%0A
+  return coalbin.length;%0A
 %7D;%0A%0Avar moun
@@ -744,16 +744,37 @@
 ion() %7B%0A
+  var coalMined = %5B%5D%0A
   amount
@@ -899,27 +899,29 @@
 ();%0A    coal
-b
+M
 in
+ed
 .push(coal);
@@ -925,16 +925,36 @@
 l);%0A  %7D%0A
+  return coalMined;%0A
 %7D;%0A%0Avar 
@@ -972,24 +972,41 @@
  = function(
+myCoalbinNotYours
 ) %7B%0A  if(coa
@@ -1002,23 +1002,33 @@
  %7B%0A  if(
-c
+myC
 oalbin
+NotYours
 .pop()) 
@@ -1203,18 +1203,16 @@
 power%22);
-  
 %0A    // 
@@ -1295,19 +1295,49 @@
 urn 
-true; %0A%7D;%0A%0A
+myCoalbinNotYours;%0A%7D;%0A%0Avar amountMined = 
 star
@@ -1370,30 +1370,27 @@
 mined %22+
-coalbin.length
+amountMined
 +%22 piece

Update globals-are-evil.js