-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPopsicles-basic.js
More file actions
61 lines (52 loc) · 2.27 KB
/
Popsicles-basic.js
File metadata and controls
61 lines (52 loc) · 2.27 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
51
52
53
54
55
56
57
58
59
60
61
/* ---------------------------------------------------------------------------------------------------------------------
You have a box of popsicles and you want to give them all away to a group of brothers and sisters.
If you have enough left in the box to give them each an even amount you should go for it! If not,
they will fight over them, and you should eat them yourself later.
Task
Given the number of siblings that you are giving popsicles to, determine if you can give them each an even amount or
if you shouldn't mention the popsicles at all.
Input Format
Two integer values, the first one represents the number of siblings, and the second one represents the number of popsicles
that you have left in the box.
Output Format
A string that says 'give away' if you are giving them away, or 'eat them yourself' if you will be eating them yourself.
Sample Input
3 9
Sample Output
give away
--------------------------------------------------------------------------------------------------------------------- */
var a,b;
popSicles = (a,b) => {
if((a-b) > 0){
console.log(`Siblings are ${a} - greater than the Popsicles - ${b}: Eat them yourself`);
} else if(a==1) {
console.log(`Give Away: There is only ${a} sibling`);
} else if (a == b){
console.log(`Give Away: Both the Popsicles ${b} and the number of Siblings ${a} are same`);
} else if ((b%a) == 0){
console.log(`Give Away: We can give each sibling equally of ${b/a} Popsicles`);
} else if((b%a) != 0){
console.log(`Eat them yourself ${Math.ceil(b/a)} is not equal to Zero`);
}
};
popSicles(1,9); // 3 is the number of siblings and 9 is the number of popsicles
popSicles(3,9);
popSicles(1,1);
popSicles(1,5);
popSicles(10,9);
popSicles(100,9);
popSicles(99,101);
popSicles(99,100);
popSicles(99,99);
/* OUTPUT */
/*
Give Away: There is only 1 sibling
Give Away: We can give each sibling equally of 3 Popsicles
Give Away: There is only 1 sibling
Give Away: There is only 1 sibling
Siblings are 10 - greater than the Popsicles - 9: Eat them yourself
Siblings are 100 - greater than the Popsicles - 9: Eat them yourself
Eat them yourself 2 is not equal to Zero
Eat them yourself 2 is not equal to Zero
Give Away: Both the Popsicles 99 and the number of Siblings 99 are same
*/