-
Notifications
You must be signed in to change notification settings - Fork 0
/
theCouponCode.js
17 lines (15 loc) · 911 Bytes
/
theCouponCode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//PARAMETERS: dates passed as strings "Month Date, Year"
//RESULT: a function which verfifies that a coupon
// code is valid and not expired.
//EXAMPLE: checkCoupon("123", "123", "July 9, 2015", "July 9, 2015") === true
//PSEUDOCODE: convert string to integer
// use relational operator to verify coupon code
// use a equality operator to determine if coupon has expired
// use a conditional operator for overall validation
// All within in a ternary expression
function checkCoupon(enteredCode, correctCode, currentDate, expirationDate){
return enteredCode === correctCode && Date.parse(expirationDate) >= Date.parse(currentDate)
}
function checkCoupon(enteredCode, correctCode, currentDate, expirationDate){
return enteredCode===correctCode && new Date(currentDate) <= new Date(expirationDate);
}