-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmilkBuyingChallenge.js
More file actions
50 lines (49 loc) · 1.46 KB
/
Copy pathmilkBuyingChallenge.js
File metadata and controls
50 lines (49 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Challenge 1: Use arguments to tell how many bottles of milk to buy
function getMilk(bottles) {
console.log("leaveHouse");
console.log("moveRight");
console.log("moveRight");
console.log("moveUp");
console.log("moveUp");
console.log("moveUp");
console.log("moveUp");
console.log("moveRight");
console.log("moveRight");
console.log("buy "+bottles+" bottles of milk.")
console.log("moveLeft");
console.log("moveLeft");
console.log("moveDown");
console.log("moveDown");
console.log("moveDown");
console.log("moveDown");
console.log("moveLeft");
console.log("moveLeft");
console.log("enterHouse");
}
getMilk(12);
// Challenge 2: Use arguments to tell how much money is the limit and calculate max bottles of milk for given pricePerBottle and return change
function getMilk(money,pricePerBottle) {
var bottles= Math.floor(money/pricePerBottle);
console.log("leaveHouse");
console.log("moveRight");
console.log("moveRight");
console.log("moveUp");
console.log("moveUp");
console.log("moveUp");
console.log("moveUp");
console.log("moveRight");
console.log("moveRight");
console.log("buy "+bottles+" bottles of milk.");
console.log("moveLeft");
console.log("moveLeft");
console.log("moveDown");
console.log("moveDown");
console.log("moveDown");
console.log("moveDown");
console.log("moveLeft");
console.log("moveLeft");
console.log("enterHouse");
var change=money%pricePerBottle;
return change;
}
getMilk(5,2);