HTML Academy
Shall we play?
Objects2/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 attempt number one
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Players, let’s start!

Now that we’ve made sure that dice roll is working, we need to enter players who will roll these dice and get game points for rolling them.

The players will be Muffin and his friend Rudolph. Add variables to store the points and name of each player in order to find and log the winner’s results in the console in the future. For each player, two variables will be created: name and points.

Since we have a function inside of which game points will be accrued and logged in the console, variables with names and points of players should be transferred to this function. Yes, the runGame function will now have five parameters, but what can you do? Such is the game.

By the way, note that the names of variables and function parameters do not match. A variable that stores the number of dice is called diceNumber, and the name of the corresponding parameter quantity. The runGame function is an abstract one. Let us not forget that the game can change. For example, cats will want to play cards or the game will be played by people. That is why we will call the parameters that store the data of the players abstractly: firstPlayerName, firstPlayerPoints, secondPlayerName, secondPlayerPoints.

Comments

  • script.js
JavaScript
var diceNumber = 2; var runGame = function (quantity) { console.log(muffin.throwDice(quantity, quantity * 6)); }; runGame(diceNumber);

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

After diceNumber and before the runGame function, declare a variables:

  1. firstCatName with the name of the first player 'Muffin'.
  2. firstCatPoints with value 0.
  3. secondCatName, which contains the name of the second player 'Rudolph'.
  4. secondCatPoints with value 0.
  5. Add parameters firstPlayerName, firstPlayerPoints, secondPlayerName, secondPlayerPoints to function runGame after parameter quantity and transfer the new variables to this function after argument diceNumber.

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.