const calculateTip = (a, r) => {
const tips = {
terrible: 0,
poor: 5,
good: 10,
great: 15,
excellent: 20
}
return Math.ceil(tips[r.toLowerCase()] / 100 * a) || 'Rating not recognised'
}
можете подсказать плз чем плоха такая реализация, чет не могу понять как построить правильно условие при а 0 если а === 0 то ретурн 0 /:
условие задачи
Complete the function, which calculates how much you need to tip based on the total amount of the bill and the service.
You need to consider the following ratings:
Terrible: tip 0%
Poor: tip 5%
Good: tip 10%
Great: tip 15%
Excellent: tip 20%
The rating is case insensitive (so "great" = "GREAT"). If an unrecognised rating is received, then you need to return: 'Rating not recognised'