forked from turingschool-examples/javascript-foundations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspa.js
51 lines (46 loc) · 1.03 KB
/
spa.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function createCustomer(name, bill, bookingsArr = []) {
var customerObj = {
name: name,
bill: bill,
bookings: bookingsArr,
};
return customerObj;
}
function greeting(customerObj) {
if (customerObj.bookings.length === 0) {
return `${customerObj.name}! Welcome to Happy Spa`;
} else {
return `${customerObj.name}! Welcome back to Happy Spa`;
}
}
function createService(service, cost) {
if (service === undefined) {
return "Please provide service name and cost.";
}
var serviceObj = {
name: service,
cost: cost,
};
return serviceObj;
}
function bookServices(nameObj, serviceObj) {
nameObj.bookings.push(serviceObj.name);
nameObj.bill += serviceObj.cost;
return nameObj;
}
function applyGiftCard(services, num) {
var servicesArr = [];
for (var i = 0; i < services.length; i++) {
if (services[i].price <= num) {
servicesArr.push(services[i].name);
}
}
return servicesArr;
}
module.exports = {
createCustomer,
greeting,
createService,
bookServices,
applyGiftCard,
};