• Theory
  • Theory

Fourth program: “Mad Dryer”

You are ready to write the fourth program that the boss will test with his own paws. Here is the technical assignment:

Meow! I’m tired of diet and exercise, and that’s why I want to know how many more days I need to exercise to achieve the right weight for the event.

Input data: weight at the beginning of the diet and weight at the end of the diet.

Work logic: if I exercise and diet, I lose 5% of my weight per day (you can’t really gain any weight on dry food, and my exercise sessions are harsh). And I exercise as long as my weight is greater than desired.

Just count how many days you need to stick to this routine and write the number in the days variable.

Of course, for this program, it is more convenient to use while, since the number of iterations is unknown beforehand.

Note that every day Muffin loses 5% of his weight. And the weight is updated every day. For example, if at first the Muffin weighed 5 kg (that is 5000 grams), then the next day his weight will be 4750 grams. And on the second day, he will lose 5% of the new weight, that is, from 4750 grams. Take this into account when calculating.

To call the 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.