Skip to content

Commit 61e5e82

Browse files
committed
done
1 parent 288da96 commit 61e5e82

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
### Here are some simple javaScript problem-solving solutions. It's for beginners.
22

3-
<h5 style={color:'green'}>AnimalCount</h5>
3+
#### AnimalCount
44
<p>Suppose you are going through a jungle. Now there are many animals around you. You want to count these. But the number of creatures is growing as deep as you want. There are 50 animals in the first 10 miles and 100 animals in the next 10 miles. There are 200 animals per mile in the next mile. Now how to calculate these is shown inside animalCount.</p>

animalCount.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function animalCount (depth) {
2+
let animal = 0;
3+
if(depth <= 10){
4+
animal = depth * 50;
5+
}
6+
else if(depth <= 20){
7+
const mile = depth - 10;
8+
const firstPart = 10 * 50;
9+
const secondPart = mile * 100;
10+
animal = firstPart + secondPart;
11+
}
12+
else{
13+
const mile = depth - 20;
14+
const firstPart = 10 * 50;
15+
const secondPart = 10 * 100;
16+
const finalPart = mile * 200;
17+
animal = firstPart + secondPart + finalPart;
18+
}
19+
return animal;
20+
}
21+
const result = animalCount(22);
22+
console.log(result);
23+
//expected output: 1900

0 commit comments

Comments
 (0)