• Theory
  • Theory

Third program: “Protein shake!”

The time has come to create the third own program, which will help Muffin properly stock up on protein for any period, for example, for 15 or 25 days.

The peculiarity of Muffin’s diet is that the amount of protein on even and odd days is different. Anyway, here is the technical assignment written by Muffin’s paw:

Meow! The program should calculate how much protein I need to drink for the entire training period.

On even days, I drink 200 grams. On odd days 100 grams.

The number of days is stored in variable days, the amount of protein to consume on an even day in variable evenDayAmount, protein on an odd day in variable oddDayAmount, and the result must be written into variable total, which is already defined.

In this program, it is convenient to use a loop in which the amount of protein will accumulate. Note that in the task, you work with days, therefore days must be counted from 1, and not from 0.

In order for the task to be solved correctly, we must determine how many even and odd days there are in a period. Use the % operator to do this (remainder in division).

To call Muffin to check the program, press the Hey boss, here’s your program! button located in the console.

  • index.html
HTML
HTML

You’ve gone to a different page

Click inside the mini-browser to shift the focus onto this window.

100%
Granny Muffin

Easy there, pal!

To access the Loops challenges in the JavaScript programming, you need to sign up and subscribe first.