Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                function log(x){
console.log(x)
}
function fix2(val){
	return val.toFixed(2);
}
let tenderValues= {
"PENNY": 0.01,
"NICKEL": 0.05,
"DIME": 0.1,
"QUARTER": 0.25,
"ONE": 1,
"FIVE": 5,
"TEN": 10,
"TWENTY": 20,
"ONE HUNDRED": 100
}
function checkCashRegister(price, cash, cid) {
  let miserlyCid = [];

for (var i = 0; i < cid.length; i++){
    miserlyCid[i] = cid[i].slice();
} 
  
  var totalOwed= fix2(cash-price)
  let totalCid= 0;
  
  for (let i=0; i<cid.length; i++){
  totalCid+=cid[i][1]
  }
  totalCid= fix2(totalCid)
  let moneyStillOwed= totalOwed
  log('moneyStillOwed: '+moneyStillOwed)
  if(totalOwed==totalCid){
  return {status: "CLOSED", change: cid}
  }
  log('this is cid before greed : '+cid);

  let change=[]
  let status= "OPEN"
  for(let i=cid.length-1; i>=0; i--){
  log('this is the i value of the greedy loop: '+i);
	if(tenderValues[cid[i][0]]<=moneyStillOwed && cid[i][1]>0){
	//in here is counting up the total of each drawer denomination
	//and storing in x each time we look at the next drawer in the array represented by cid[i][0]
	 let x=0
	 while((x+tenderValues[cid[i][0]])<=moneyStillOwed && cid[i][1]>0){
		cid[i][1]-=tenderValues[cid[i][0]]
		x+=tenderValues[cid[i][0]]    
	 }	 
	moneyStillOwed-=x
	moneyStillOwed=fix2(moneyStillOwed)
	 log('in greedy this is the total tender value left in the ' +cid[i][0]+' register locker :'+ cid[i][1])
	 change.push([cid[i][0],x])
	}
  } 
  if ( moneyStillOwed != 0 && totalCid< moneyStillOwed){
  //now I will add if the money owed is not zero AND the total in drawer is less than moneyStillOwed
	status= "INSUFFICIENT_FUNDS";
	change=[]
  } else {
  log('this is Miserly cid in miserly before the miserly loop: '+miserlyCid);
  
    let change=[]
  let status= "OPEN"
  for(let i=0; i<=cid.length-1; i++){
  //log('this is the i value in miserly: '+i);
	if(tenderValues[cid[i][0]]<=moneyStillOwed && cid[i][1]>0){
	//in here is counting up the total of each drawer denomination
	//and storing in x each time we look at the next drawer in the array represented by cid[i][0]
	 let x=0
	 while((x+tenderValues[cid[i][0]])<=moneyStillOwed && cid[i][1]>0){
		cid[i][1]-=tenderValues[cid[i][0]]
		x+=tenderValues[cid[i][0]]    
	 }	 
	moneyStillOwed-=x
	moneyStillOwed=fix2(moneyStillOwed)
	 log('in miserly this is the total tender value left in the ' +cid[i][0]+' register locker :'+ cid[i][1])
	 change.push([cid[i][0],x])
	}
  } 
  
  
  }
  let obj= {
  status: status, 
  change: change
  }
 log(obj) 
}

checkCashRegister(.70, 1, [["PENNY", 0], ["NICKEL", 0], ["DIME", .3], ["QUARTER", .25], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])
              
            
!
999px

Console