HTML Academy
Career start
Introduction to programming2/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
Console log
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Making the program a bit more complicated

Just 21 calories! Muffin is happy! Happy about your first program, too.

Second task: write a program for calculating the nutritional value of lunch and dinner. For lunch, Muffin loves his crunchy cat food, around 80 grams. For dinner, it’s the same fragrant, crunchy dry food, but a bit more, around 120 grams. That’s what a cat needs to get ready for nightly training. Yes, food diversity is not Muffin’s strongest suit.

You cannot write this program with a single line of code, you’ll need two. Don’t forget about the ; mark.

By the way, in JavaScript, you can use special commands for tips. They are called comments, and the code inside is never executed. As a rule, comments are used for notes to yourself, to other developers or yourself in the future. There two types of comments: one-line and multiline. Example of comments:

// This line will not be executed. One-line comment.

/*
None of these lines of code will be executed.
Because it’s a multi-line comment.
*/

Comments

  • script.js
JavaScript
// Enter the program code below

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

Write a program that calculates the nutritional value of Muffin’s lunch and dinner.

  1. To do this, enter line 80 * (400 / 100); in the editor.
  2. Beneath it, enter 120 * (400 / 100); and take a look at the result in the console.

It turns out that 100 grams of his food contain around 400 calories.

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.