Tag: Push otherwise performs function nbsp Loop log Assignment Func
var n = 0//How many bottles are left now plus how many bottles are won?
var x = 5//Initial number of bottles
var y = 0//How many bottles are left in addition to the drink
var z = total number of 0;//
var arr = []//defines an array of stored values
Arr.push (x);//Add the initial bottle number to the array first
Procedure 1
var fn = function (s) {
y = s-4; How many bottles are left?
s = y + parseint (S/4) + parseint (S/2);//How many bottles are left plus how many are won?
n = s//assignment to the above n
Arr.push (n);//Add to Array
if (n>=4) {//If there are many bottles left plus how many bottles are greater than or equal to 4
FN (n);//Continue executing program 1
}else{//otherwise
FN1 (n)//Execute Program 2
}
}
Procedure 2
var fn1 = function (s) {
y = How many bottles are left in s-2;//
s = y + parseint (S/2);//How many bottles are left plus how many are won?
n = s//assignment to the above n
Arr.push (n);//Add to Array
if (n>=2) {//If there are many bottles left plus how many bottles are greater than or equal to 2
FN1 (n);//Continue to execute program 2
}
}
FN (x)//Execute Program 1
for (Var i=0;i<arr.length;i++) {
z + = arr[i]//Loop array add up all the numbers
}
Console.log (z);//Get Totals and Print
Logic:
1, first drink 4 bottles, the remaining 1 bottles, plus 2 bottles and 1 bottles, left 4
2, then drink 4 bottles, 0 bottles left, plus 2 bottles and 1 bottles, leaving 3 bottles.
3, then drink 2 bottles, the remaining 1 bottles, plus 1 bottles, the remaining 2 bottles
4, then drink 2 bottles, the remaining 0 bottles, plus 1 bottles, the remaining 1 bottles
5, add up the number is, 5+4+3+2+1 = 15
JavaScript Calculation Beer 2 yuan a bottle, 4 cover for a bottle, 2 bottles for a bottle, 10 yuan to drink the most bottles