Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Building a Cash Register using JavaScript
WhatsApp
Darin
Nov 02
2015
1.4
k
0
0
Complete.zip
Building a Cash Register
var cashRegister = {
total: 0,
add: function (itemCost)
{
this
.total += itemCost;
},
scan: function (item, quantity)
{
switch
(item)
{
case
"pencil"
:
this
.add(0.98 * quantity);
break
;
case
"pen"
:
this
.add(1.23 * quantity);
break
;
case
"magazine"
:
this
.add(4.99 * quantity);
break
;
case
"eraser"
:
this
.add(0.45 * quantity);
break
;
}
}
s
};
// scan each item 4 times
cashRegister.scan(
"pencil"
, 4);
cashRegister.scan(
"pen"
, 4);
cashRegister.scan(
"magazine"
, 4);
cashRegister.scan(
"eraser"
, 4);
//Show the total bill
console.log(
'Your bill is '
+ cashRegister.total);
OUTPUT
Your bill
is
30.6
Building a Cash Register
Javascript
Up Next
Building a Cash Register using JavaScript