HTML Academy
Making the program a bit more complicated
Introduction to programming3/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
Data types
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Console log

Muffin is not happy this time! And it’s not about those 480 calories in his dinner (although it’s most likely the case).

The thing is that the program shows one number only, and the boss wants to see two: for lunch and for dinner. Preferably with text explanations.

Let’s work on our code. But first, let’s try to understand how the current version works.

JavaScript runs programs sequentially, command after command, and outputs the result of the latest executed command to the console. In the current version of our program, the last command returns 480. And that’s what we see in the console.

In order to output additional information to the console, you can use a special command:

console.log(data for console output);

This command can be used anywhere in the program to output not just the results of command execution, but text tips as well. For example:

console.log(2 * 2);

Text tips, unlike operation results, must be enclosed in quotation marks:

console.log('Muffin says hi!');

Let’s get to work!

Comments

  • script.js
JavaScript
80 * (400 / 100); 120 * (400 / 100);

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

Improve the program for calculating the nutritional values of lunch and dinner.

  1. Add a console.log('Calorific value of lunch'); command before the 80 * (400 / 100); command
  2. then replace 80 * (400/100); command with console.log(80 * (400 / 100)).
  3. Add a console.log('Calorific value of dinner'); command before 120 * (400 / 100);
  4. then replace 120 * (400 / 100); with a console.log(120 * (400 / 100)); command.

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.