- Lab
- Core Tech

Building a Simple Shopping Game with Object-oriented JavaScript

Path Info
Table of Contents
-
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 pressEnter
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 runninggit checkout module1-solution
to switch branches. -
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 theProduct
&MagicProduct
data required for the game to function. ### Solution To view the solution, rungit diff origin/master..module2-solution
in the Terminal, and pressEnter
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 runninggit checkout module2-solution
to switch branches. -
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 pressEnter
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 runninggit checkout module3-solution
to switch branches. -
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 pressEnter
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 runninggit checkout module4-solution
to switch branches. -
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 pressEnter
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 runninggit checkout module5-solution
to switch branches. -
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 pressEnter
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 runninggit checkout module6-solution
to switch branches.
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.