HTML Academy
Complex data types
Introduction to programming6/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
Variables
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Unknown data

Sooner or later, it was supposed to happen. Check out a new task from Muffin.

Third task: “Write a program for calculating the caloric value of my breakfast. I eat milk for breakfast. I want to enter the amount I ate and see its caloric value.”

Why didn’t he put it this way right from the start?! Let’s forgive Muffin. He is a nocturnal, solitary predator, fast and agile, but not as savvy as his colleagues, raccoons. So he will be making tasks more difficult slowly.

It won’t be easy to complete this task from the first attempt, so we will do it step by step.

We have already written code for a program that worked with known data. This data was defined right in the code of the program.

However, you will be mostly working with data unknown during the start of the program. For example, you will be capturing the user’s input and process it.

To begin with, let’s learn to receive data from the user. That is, from the boss a.k.a Muffin. To do it, let’s page him using a special command:

muffin.ask('question for the boss');

This program exists in our console only. It is not built into JavaScript because Muffin doesn’t allow the developers of the language to do it (in spite of many requests). If you build the command into the language, the boss’s pager will explode from so many messages coming in.

You will also learn how to create your own commands in programs, give them names and access them for operations. We’ll see how it’s done in future courses. Try collecting data from Muffin. Don’t forget that a question is a string, and you need to enclose it in quote marks: 'string'.

Comments

  • script.js
JavaScript
console.log('Brekkie-meter v0.1 is launched'); // Enter the muffin.ask command on the next line

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. In the editor, enter the muffin.ask command with the following question: “Boss, how many grams of milk have you had?”

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.