HTML Academy
Tenth program: “Golden ball”
Objects22/30
Back to the list of tasks
  • 1. Shall we play?
  • 2. Players, let’s start!
  • 3. My attempt number one
  • 4. Hello, object!
  • 5. Reading from the object
  • 6. Count off!
  • 7. Overriding object properties
  • 8. Passing object by a link
  • 9. My game
  • 10. Giving out the attempts
  • 11. Who is the winner?
  • 12. Announce the entire list, please
  • 13. Looking for a cat with great results
  • 14. No one will hide
  • 15. New conditions
  • 16. Hard to come across
  • 17. Let’s bring it all to light
  • 18. Roll the dice, gentlemen cats!
  • 19. Let’s make adjustments
  • 20. Summary of “Objects”. Part 1
  • 21. Tenth program: “Golden ball”
  • 22. Build it yourself!
  • 23. My first method
  • 24. Implementing methods
  • 25. Object as a dictionary
  • 26. Bracket notation
  • 27. Let’s not forget about the context
  • 28. Store check
  • 29. Summary of “Objects”. Part 2
  • 30. Eleventh program: “The house that Muffin built”
My first method
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Build it yourself!

Meow!

Stop messing around, time to work!

We have a new project, we need to write a computer store. It’s a serious customer: everything must be done in the best possible way. Here is a small technical assignment:

  • The user selects the computer, and the program logs the result of the order.
  • The message should include technical characteristics and the final price of the product.
  • There is a base price for any computer, and the final amount depends on each technical indicator of the device.

I’m waiting for the result! Don’t let me down!

As before, we will analyze the task to understand what the program will consist of.

Obviously, we won’t be able to cope without a function. We will transfer the selected computer to the function and get the final amount. When performing calculations, we must take into account the base price of the device and the cost of each characteristic. For example, the prices of computers with a screen of 13 and 15 inches will be different. It turns out, each device has indicators: the base price and technical characteristics (RAM, processor and display size). In other words, we have several properties pertaining to one entity, a computer. Have you guessed where we will store it? That’s right, in the object.

As a result, we’ll get a computer configurator. In the object, we’ll store the computer and its characteristics, and the object will be stored in the body of the function. When choosing a device, we will call the configurator function, which will write to the computer’s object its characteristics, calculate the price and return it.

First, create the buildComputer function and the computer object inside it, and then check that the function returns it.

Comments

  • script.js
JavaScript

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 function buildComputer with parameters memory, display, processor.
  2. Inside the function, create object computer with properties basicPrice: 5000, processor: processor, display: display, memory: memory.
  3. Return the computer object from the function.
  4. Call the function using arguments 8, 13, 'i7' and record the result of the call in variable myComputer.
  5. Log the myComputer variable in the console.

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.