Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Core Tech
Labs

Building a Simple Shopping Game with Object-oriented JavaScript

Lab platform
Lab Info
Level
Intermediate
Last updated
Sep 22, 2025
Duration
1h 26m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Define the player object

    In this module we will start implementing the Shopping Master game by defining the objects and classes required for the game. We will gradually add on to the script to make use of them to implement our game in the next modules. By the end of this module, you'll have defined all the objects and classes along with their properties, getters and setters, other methods and established the links between classes (i.e. Inheritance). ### Solution To view the solution, run git diff origin/master..module1-solution in the Terminal, and press Enter to see the next lines of the difference.

    You may also browse the files of the solution by stashing your changes with git stash and running git checkout module1-solution to switch branches.

  2. Challenge

    Find the property names of Product() using the Object.keys() method

    In this module, we will populate the master data required for the Shopping Master game in to an array. We will use the Product() & MagicProduct() object types to create sample products using the given master data map. By the end of this module, you'll have loaded the Product & MagicProduct data required for the game to function. ### Solution To view the solution, run git diff origin/master..module2-solution in the Terminal, and press Enter to see the next lines of the difference.

    You may also browse the files of the solution by stashing your changes with git stash and running git checkout module2-solution to switch branches.

  3. Challenge

    Implement findProductById() function

    In this module we are going to complete two functions, findProductById() and generateProductId(). These two functions will be used in the next step of the Shopping Master game for retrieving a specific product from the list of available products. ### Solution To view the solution, run git diff origin/master..module3-solution in the Terminal, and press Enter to see the next lines of the difference.

    You may also browse the files of the solution by stashing your changes with git stash and running git checkout module3-solution to switch branches.

  4. Challenge

    Calculate the Total Bill

    In this module we will implement the player's point calculation logic of the Shopping Master game. To do so we need to complete the three functions: calculateBill(), findPointsForExpDate() and claculatePoints(). ### Solution To view the solution, run git diff origin/master..module4-solution in the Terminal, and press Enter to see the next lines of the difference.

    You may also browse the files of the solution by stashing your changes with git stash and running git checkout module4-solution to switch branches.

  5. Challenge

    Assign player name

    In this module we will implement the shopping functionality which will be the main part of the game. For this we need to add a few lines of code inside init() function and shop() function. By the end of this module you'll have implemented the initialization function of the game by initializing the player object by assigning values to its properties. In addition, the shopping functionality is implemented by offering products to the player, setting the item count and the player's score as the player continues to play the game and finally the player's status based on the points earned. ### Solution To view the solution, run git diff origin/master..module5-solution in the Terminal, and press Enter to see the next lines of the difference.

    You may also browse the files of the solution by stashing your changes with git stash and running git checkout module5-solution to switch branches.

  6. Challenge

    Create Rating object

    In this final module, we will implement the game exit functionality by completing rateAndExit(), exitLost() and exitWon() functions. By the end of this module you'll have fully implemented the Shopping Master game and you should simply be able to run the game once you uncomment the code snippet right above the main() function. ### Solution To view the solution, run git diff origin/master..module6-solution in the Terminal, and press Enter to see the next lines of the difference.

    You may also browse the files of the solution by stashing your changes with git stash and running git checkout module6-solution to switch branches.

About the author

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight