Let's move on! Now let's learn how to implement more complex loops.
One day, the host at a wedding decided to entertain the guests and set a rule: each guest who comes makes a toast, and all guests drink for the health of the newlyweds.
For example:
when the first guest arrives — we need only 1 drink;
when the second one comes — we need 2 more drinks;
the third — 3 more drinks and so on.
If there are 5 guests, then we need 15 drinks in total (1 + 2 + 3 + 4 + 5).
If 10, then 55 drinks (1 + 2 + 3 + ... + 10).
Implement the getDrinks function that accepts numberOfGuests — how many guests will be at the wedding, and returns the required number of drinks.
More examples:
getDrinks(0); // 0 - no guests - no drinks
getDrinks(2); // 1 + 2 = 3
getDrinks(6); // 1 + 2 + 3 + 4 + 5 + 6 = 21
Check the Sum of Numbers From 1 to n theory section to find out how to sum numbers in a loop.