Great. Now we need to process the data and show the result to the customer.
Let’s agree on the formula for calculating the caloric value. We know how many grams of milk Muffin drinks. We’ve also learned that he now drinks fatter milk containing 50 calories per 100 grams.
To calculate the total number of calories, we need to multiply the number of grams by the number of calories per gram (we need to divide 50 by 100 first). Here is the final formula:
numberOfGramsVariable * 50 / 100
Let’s save the result to another variable and send a message to the console. The task is solved, all we need is to write code now!
You are now ready for writing your own program from scratch all on your own. You will do it the next task. You will get the technical specification from Muffin (it will also explain where the boss got the idea of keeping track of his calories). He will also personally test your program. Don’t worry, the task is simple enough.
Final tip. When you start writing your code from scratch, you might need additional variables. Remember, there are several variable naming rules:
The name of a variable must start with a Latin letter and can contain Latin letters and numbers only.
You cannot use special reserved words, such as var or if as variable names. Here is a complete list of these reserved words.
console.log('Brekkie-meter v0.1 is launched');
var milkInGrams = keks.ask('Boss, how many grams of milk have you had?');
console.log('Brekkie-meter has received milk data. ' + milkInGrams + ' grams consumed.');
The code has changed, click “Run” or turn autorun on.
Declare variable breakfastCalories,
use it to save the result calculated with the formula described in the theory section.
Log in the console a message made up of three fragments: string 'Calorific value of breakfast: ', variable breakfastCalories, line ' calories, boss!'.
Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.
Forgot to connect your email to the profile? Email us and we’ll help.