TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Building a Cash Register using JavaScript
Darin
Nov 02
2015
Code
1.2
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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