HTML Academy
Release of Brekkie-meter v0.1, part 1
Introduction to programming13/15
Back to the list of tasks
  • 1. Career start
  • 2. Making the program a bit more complicated
  • 3. Console log
  • 4. Data types
  • 5. Complex data types
  • 6. Unknown data
  • 7. Variables
  • 8. Declaring and assigning variables
  • 9. Operations
  • 10. Operations order
  • 11. A few more operations
  • 12. Release of Brekkie-meter v0.1, part 1
  • 13. Release of Brekkie-meter v0.1, part 2
  • 14. Summary of “Getting to know JavaScript”
  • 15. First program: MufFit v0.1
Summary of “Getting to know JavaScript”
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Release of Brekkie-meter v0.1, part 2

Great. Now we need to process the data and show the result to the boss.

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:

  • Variable names are case-sensitive in JavaScript. myname and myName are two different variables.
  • 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.

Comments

  • script.js
JavaScript
console.log('Brekkie-meter v0.1 is launched'); var milkInGrams = muffin.ask('Boss, how many grams of milk have you had?'); console.log('Brekkie-meter has received milk data. ' + milkInGrams + ' grams consumed.');

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

Console

The code has changed, click “Run” or turn autorun on.

Result

Goalscompleted
  1. Declare variable breakfastCalories,
  2. use it to save the result calculated with the formula described in the theory section.
  3. Log in the console a message made up of three fragments: string 'Calorific value of breakfast: ', variable breakfastCalories, line ' calories, boss!'.

Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

VISAMastercard

Log in

or

Forgot your password?

Sign up

Sign up

or
Log in

Restore access

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.