Featured resource
Forrester Wave Report 2025
Pluralsight named a Leader in the Forrester Wave™

Our tech skill development platform earned the highest scores possible across 11 criteria.

Learn more
  • Labs icon Lab
  • Core Tech
Labs

Building a Simple Shopping Game with Object-oriented JavaScript

Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 1h 34m
Published
Clock icon Apr 14, 2023

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.

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.

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.