Javascript Conditional Statement
- or -
Post a project like this3329
£60(approx. $75)
- Posted:
- Proposals: 5
- Remote
- #700212
- Awarded
Description
Experience Level: Intermediate
General information for the website: Bond Calculator
Num. of web pages/modules: 1
Description of every page/module: I am looking to achieve this.
For a date of the 27 Feb 2015 I need to calculate whether this is before / after or equal to the following variables, all are strings and formatted in DD-MM
var settlement_date = '27 Feb 2015'; //This is the exception to the above formatting
var first_payment = '24-01';
var first_record_date = '17-01';
var second_payment = '24-07';
var second_record_date = '17-07';
var next_entitlement_date;
The logic is as follows
// if the settlement date is after the first_payment date
// if the settlement date is before the second_payment date
// last_coupon_payment = first_payment
// next_coupon_payment = second_payment
// record_date = second_record_date
// if the settlement date is after the second_payment date
// last_coupon_payment = second_payment - 1 Year
// next_coupon_payment = first_payment
// record_date = first_record_date
// if the settlement date is equal to the second_payment date
// last_coupon_payment = first_payment
// next_coupon_payment = second_payment
// record_date = second_record_date
// if the settlement date is before the first_payment date
// if the settlement date is before the second_payment date
// last_coupon_payment = first_payment
// next_coupon_payment = second_payment
// record_date = second_record_date
// if the settlement date is after the second_payment date
// last_coupon_payment = second_payment - 1 Year
// next_coupon_payment = first_payment
// record_date = first_record_date
// if the settlement date is equal to the second_payment date
// last_coupon_payment = second_payment
// next_coupon_payment = first_payment
// record_date = first_record_date
Also I need to evaluate the settlement_date relative to the *_record_date and set the variable next_entitlement_date to either the first_payment or second_payment depending on the outcome.
I have included a JSBin (http://jsbin.com/setehatuxo/2/edit) of my existing code which is I feel overly complex and I need some help to resolve this conditional pit that I am in.
Description of requirements/features: To make the conditional work in all circumstances
Extra notes:
Num. of web pages/modules: 1
Description of every page/module: I am looking to achieve this.
For a date of the 27 Feb 2015 I need to calculate whether this is before / after or equal to the following variables, all are strings and formatted in DD-MM
var settlement_date = '27 Feb 2015'; //This is the exception to the above formatting
var first_payment = '24-01';
var first_record_date = '17-01';
var second_payment = '24-07';
var second_record_date = '17-07';
var next_entitlement_date;
The logic is as follows
// if the settlement date is after the first_payment date
// if the settlement date is before the second_payment date
// last_coupon_payment = first_payment
// next_coupon_payment = second_payment
// record_date = second_record_date
// if the settlement date is after the second_payment date
// last_coupon_payment = second_payment - 1 Year
// next_coupon_payment = first_payment
// record_date = first_record_date
// if the settlement date is equal to the second_payment date
// last_coupon_payment = first_payment
// next_coupon_payment = second_payment
// record_date = second_record_date
// if the settlement date is before the first_payment date
// if the settlement date is before the second_payment date
// last_coupon_payment = first_payment
// next_coupon_payment = second_payment
// record_date = second_record_date
// if the settlement date is after the second_payment date
// last_coupon_payment = second_payment - 1 Year
// next_coupon_payment = first_payment
// record_date = first_record_date
// if the settlement date is equal to the second_payment date
// last_coupon_payment = second_payment
// next_coupon_payment = first_payment
// record_date = first_record_date
Also I need to evaluate the settlement_date relative to the *_record_date and set the variable next_entitlement_date to either the first_payment or second_payment depending on the outcome.
I have included a JSBin (http://jsbin.com/setehatuxo/2/edit) of my existing code which is I feel overly complex and I need some help to resolve this conditional pit that I am in.
Description of requirements/features: To make the conditional work in all circumstances
Extra notes:
Justin E.
100% (1)Projects Completed
3
Freelancers worked with
3
Projects awarded
75%
Last project
27 Feb 2015
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies