cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              var changing = function(money, price){
  var count = parseInt(money/price),
      bottle = count,
      lid = count,
      lidRate = 4,
      bottleRate = 2;
  (function change(){
    // 兑换盖子
    if(lid >= lidRate){
      var lGet = parseInt(lid/lidRate);
      count += lGet;
      bottle += lGet;
      lid -= lGet*(lidRate-1);
      console.log('使用瓶盖'+ lGet*lidRate +'个,兑换:'+ lGet +'瓶');
      console.log('已喝:'+ count + ', 剩余瓶盖:'+ lid +', 剩余空瓶:'+ bottle);
    }
    // 兑换空瓶
    if(bottle >= bottleRate){
      var bGet = parseInt(bottle/bottleRate);
      count += bGet;
      bottle -= bGet;
      lid += bGet*(bottleRate-1);
      console.log('使用空瓶'+ bGet*bottleRate +'个,兑换:'+ bGet +'瓶');
      console.log('已喝:'+ count + ', 剩余瓶盖:'+ lid +', 剩余空瓶:'+ bottle);
    }
    // 判断剩余
    if(bottle >= bottleRate || lid >= lidRate){
      change();
    } else {
      console.log('总共喝:'+ count + ', 剩余瓶盖:'+ lid +', 剩余空瓶:'+ bottle);
    }
  })();
};
// 开始计算
changing(10, 2); 
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console