Featured resource
2026 Tech Forecast
2026 Tech Forecast

1,500+ tech insiders, business leaders, and Pluralsight Authors share their predictions on what’s shifting fastest and how to stay ahead.

Download the forecast
  • 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
Oct 29, 2026
Duration
2h 1m

Contact sales

By clicking submit, you agree to our Privacy Policy and Terms of Use, and consent to receive marketing emails from Pluralsight.
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).

    Note: This lab is designed to be completed in order. Each module builds on the code implemented in previous modules. Complete the tasks sequentially and retain your changes as you progress through the lab. Some functionality will not work until the required tasks in later modules are completed. #### Solution

    You can review the completed solution for this module using the Terminal.

    To view the changes made in Module 1, run:

    git --no-pager diff origin/master..module1-solution -- js/shoppinggame.js
    

    This displays the code added or modified to complete Module 1. Lines beginning with + indicate additions, and lines beginning with - indicate removals.

    To view the complete solution file for Module 1, run:

    git --no-pager show module1-solution:js/shoppinggame.js
    

    The complete file includes the solutions for Module 1, while tasks in later modules remain unfinished.

    Note: Reviewing the solution does not modify your code. Continue working in js/shoppinggame.js and apply any necessary corrections before moving to the next module.

  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

    You can review the completed solution for this module using the Terminal.

    To view the changes made in Module 2, run:

    git --no-pager diff module1-solution..module2-solution -- js/shoppinggame.js
    

    This displays the code added or modified to complete Module 2. Lines beginning with + indicate additions, and lines beginning with - indicate removals.

    To view the complete solution file for Module 2, run:

    git --no-pager show module2-solution:js/shoppinggame.js
    

    The complete file includes the solutions for Module 2, while tasks in later modules remain unfinished.

    Note: Reviewing the solution does not modify your code. Continue working in js/shoppinggame.js and apply any necessary corrections before moving to the next module.

  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

    You can review the completed solution for this module using the Terminal.

    To view the changes made in Module 3, run:

    git --no-pager diff module2-solution..module3-solution -- js/shoppinggame.js
    

    This displays the code added or modified to complete Module 3. Lines beginning with + indicate additions, and lines beginning with - indicate removals.

    To view the complete solution file for Module 3, run:

    git --no-pager show module3-solution:js/shoppinggame.js
    

    The complete file includes the solutions for Module 3, while tasks in later modules remain unfinished.

    Note: Reviewing the solution does not modify your code. Continue working in js/shoppinggame.js and apply any necessary corrections before moving to the next module.

  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 calculatePoints(). #### Solution

    You can review the completed solution for this module using the Terminal.

    To view the changes made in Module 4, run:

    git --no-pager diff module3-solution..module4-solution -- js/shoppinggame.js
    

    This displays the code added or modified to complete Module 4. Lines beginning with + indicate additions, and lines beginning with - indicate removals.

    To view the complete solution file for Module 4, run:

    git --no-pager show module4-solution:js/shoppinggame.js
    

    The complete file includes the solutions for Module 4, while tasks in later modules remain unfinished.

    Note: Reviewing the solution does not modify your code. Continue working in js/shoppinggame.js and apply any necessary corrections before moving to the next module.

  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

    You can review the completed solution for this module using the Terminal.

    To view the changes made in Module 5, run:

    git --no-pager diff module4-solution..module5-solution -- js/shoppinggame.js
    

    This displays the code added or modified to complete Module 5. Lines beginning with + indicate additions, and lines beginning with - indicate removals.

    To view the complete solution file for Module 5, run:

    git --no-pager show module5-solution:js/shoppinggame.js
    

    The complete file includes the solutions for Module 5, while tasks in later modules remain unfinished.

    Note: Reviewing the solution does not modify your code. Continue working in js/shoppinggame.js and apply any necessary corrections before moving to the next module.

  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

    You can review the completed solution for this module using the Terminal.

    To view the changes made in Module 6, run:

    git --no-pager diff module5-solution..module6-solution -- js/shoppinggame.js
    

    This displays the code added or modified to complete Module 6. Lines beginning with + indicate additions, and lines beginning with - indicate removals.

    To view the complete solution file for Module 6, run:

    git --no-pager show module6-solution:js/shoppinggame.js
    

    The complete file includes the solutions for all six modules.

    Note: Reviewing the solution does not modify your code. Continue working in js/shoppinggame.js and apply any necessary corrections before moving to the next module.

About the author

Buddhini is a Senior Java Engineer with 11+ year of industry experience and an Independent Consultant for Kerk Solutions and a Visiting Lecture in IT at the CINEC campus Sri Lanka.

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