-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution0019.js
20 lines (19 loc) · 1.23 KB
/
solution0019.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//////////////////8kyu Holiday VI - Shark Pontoon //////////////////
// You need to work out if the shark will get to you before you can get to the pontoon. To make it easier... as you do the mental calculations in the water you either freeze when you realise you are dead, or swim when you realise you can make it!
// Instructions:
// You are given 5 variables;
// sharkDistance = distance from the shark to the pontoon. The shark will eat you if it reaches you before you escape to the pontoon.
// sharkSpeed = how fast it can move in metres/second.
// pontoonDistance = how far you need to swim to safety in metres.
// youSpeed = how fast you can swim in metres/second.
// dolphin = a boolean, if true, you can half the swimming speed of the shark as the dolphin will attack it.
// The pontoon, you, and the shark are all aligned in one dimension.
// If you make it, return "Alive!", if not, return "Shark Bait!".
function shark(pontoonDistance, sharkDistance, youSpeed, sharkSpeed, dolphin){
if (dolphin) {sharkSpeed = sharkSpeed/2}
if (Math.round(sharkDistance/sharkSpeed > pontoonDistance/youSpeed)) {
return("Alive!")
} else if (Math.round(sharkDistance/sharkSpeed < pontoonDistance/youSpeed)) {
return("Shark Bait!")
}
}